Reputation: 15928
I have a table where every row has a hidden control as shown below
<input name="ID" id="ID" type="hidden"/>
But some of them have values and others don't. How do I filter out the rows that have no value
I know it would be something like
$('#myTable tr').filter(... ???
What I am trying to do is, get the rows where the hidden control has a value, then fetch certain controls and their values from those rows and post them using jquery ajax.
Upvotes: 3
Views: 4295
Reputation: 91299
Use the following:
$('#myTable tr').filter(function () {
return $(this).find('input[type="hidden"][value!=""]').length;
});
DEMO.
Upvotes: 3
Reputation:
Building off of João's answer, to get the row you just need to take his second option and traverse up to the parent.
$('#myTable tr input[type="hidden"][value!=""]').parent();
That is assuming the hidden input is a direct descendent of the <tr>
. Otherwise you may want to use the jQuery parents() function like so:
$('#myTable tr input[type="hidden"][value!=""]').parents('tr');
Upvotes: 2
Reputation: 5443
the selector 'input[value]'
selects all inputs having a value attribute.
$("#myTable input[value], #myTable input[value!='']").doSomthing(...);
Upvotes: 1
Reputation: 14830
Add a class to it:
<input name="ID" id="ID" type="hidden" class="someclass" />
$('#myTable tr .someclass').doSomething(...)
Upvotes: 1