How can I select the Tr
which contains in one of its children a hidden field with a开发者_如何学C specific value.
<tr id="tr1">
<td id="td1">
<input type="hidden" id="idField" value='theSpecificValue'/>
I want to select tr1
if the hidden field idField
has a specific value.
Thanks in advance.
$('#idField[value="theSpecificValue"]').closest('tr')
Although ids are supposed to be unique, so possibly ignore it and use
$('input[value="theSpecificValue"]').closest('tr')
Edit:
$("tr:has(input:hidden[value=theSpecificValue])")
The author for some reason deleted this answer. I liked it better than mine and voted it up.
Use .closest('tr')
which will transverse up the DOM, finding the closest <tr>
element and once found, will stop, unlike .parents('tr')
which will match all the way to the root (undesired)
You can select the input if it has the value, then find the row from there:
$('#idField[value=theSpecificValue]').closest('tr')
Not too sure what you are trying to get from tr but you should look up parent
so
$('#idField).parent();
would return
<td id="td1">
and then you could go up the DOM again with parent().
$(":input[value='specifiedValue']").parents("#tr1:first")
精彩评论