Search code examples
jquerytraversaltree-traversaldom-traversaljquery-traversing

Setting attributes for the first column's contents with jquery


I have the following table which is loaded dynamically into a <div>.

https://i.sstatic.net/0s0p9.png

Now I am trying to traverse into the table as to disable all the input fields in the first column titled "index". How would I go about that?

What I have come up with is the following, but it fails:

$('#output').find('tr').each().find('td').first().find('input').attr('disabled','disabled');

Solution

  • This should work as well.

    $('#output tr td:first-child input').attr('disabled', 'disabled');
    

    Everything in one selector. Tested in chrome only

    http://jsfiddle.net/QGdJF/