jQuery check if element is in a html table

Sam Deering

This code snippet recursively searches up the DOM of the parent elements of the input element to find a table element.

//filter parents by HTML table tag
$('.item :first :input[name="code"]').parents('table')

//conditional, not found parent table element
($('.item :first :input[name="code"]').parents('table').length == 0)

Length passes back 1 if found, 0 if not found.