Reputation: 119827
i have this structure in html:
<ul id="resultlist">
<li>
<input type="hidden" value="idNumber" />
<dl>
...
</dl>
</li>
</ul>
is there a one-liner method in jquery that finds the <li>
based on the child?
currently i have this in my code to find the <li>
but it's quite long:
//dynamic value
var idNumber = 2;
//finds input with value of 2
var hiddenInput = $('#resultList').find('input[value='+idNumber+']');
var listItem = hiddenInput.parent();
Upvotes: 0
Views: 82
Reputation:
If you want a one-liner, just chain the calls.
var listItem = $('#resultList input[value="'+idNumber+'"]').parent();
I also brought the input
selector into the initial one to shorten it up a bit, and I also included the missing quotation marks around the attribute value.
You could use the non-standard :has()
selector I suppose if you really want it...
var listItem = $('#resultList li:has(input[value="'+idNumber+'"])');
Upvotes: 3