By Sam Deering

jQuery check if element is in a html table

By 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.


The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account