Search code examples
jqueryjquery-selectorsdom-traversal

table row if input element consists


There is a table, how I can get tr (table row), if there consists at least one input element.

I tried like:

$('#tablename:contains(input)').closest('tr');

It doesn't work.


Solution

  • $('#tablename tr:has(input)')
    

    is what you were looking for.

    • Read about the :has() selector.

    • :contains() will look for simple text, while :has() will look for elements that match the selector.

    Or the more efficient version:

    $('#tablename tr').has('input')