Reputation: 3365
I have the following HTML :
<table>
... some other rows
<tr>
<td>
<input id="Products_0__Quantity" class="product-quantity" type="text" />
</td>
<td>
...Some other columns
</td>
</tr>
... some other rows
</table>
I have attached an event handler to a link contained in every row. I know it works,because other parts of the event handler function simply work fine. However this part doesn't :
var tr = $(this).closest('tr');
var productQuantity = tr.children('input.product-quantity').val();
After this line, productQuantity is still undefined.
What's the problem ?
Upvotes: 1
Views: 82
Reputation:
Please Try this:-
tr.find('input.product-quantity').val();
Instead of Children
Upvotes: 1
Reputation: 152
In my opinion something gone wrong in the definition of $(this), are you sure about the element you get with $(this)?
however the .find() is better than children.
Upvotes: 0
Reputation: 133453
Use .find()
instead of .children()
The
.children()
method differs from.find()
in that.children()
only travels a single level down the DOM tree while.find()
can traverse down multiple levels to select descendant elements (grandchildren, etc.) as well.
Code
tr.find('input.product-quantity').val()
Upvotes: 4