Vishwajeet
Vishwajeet

Reputation: 1703

Selection of value by jQuery

In an HTML table I want to select some items, I use jQuery in the following manner:

$(document).ready(function() 
{
  $("input[id*='chkSelectPackage1']").bind("change",function(){
    var control=$(this).closest("tr");
    var aaaaaaa=control.filter(":nth-child(5)");
  });
});

In the HTML table every row has 6 cells, in the 6th cell I have a checkbox and in the selection of this checkbox I want the value inside the 4th cell. How can I do this, I am able to find the closest 'tr' but not the children of this 'tr'

Upvotes: 0

Views: 56

Answers (1)

James Allardice
James Allardice

Reputation: 166041

The problem is the use of filter:

var aaaaaaa = control.filter(":nth-child(5)");

It should work if you use find, and use the correct index (nth-child is 1-indexed):

var aaaaaaa = control.find(":nth-child(4)");

filter looks at the top-level elements within your jQuery object. In your case, there is only one (the tr), so that won't work. find looks at descendants.

Upvotes: 2

Related Questions