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();
If you want a one-liner, just chain the calls.
I also brought the
inputselector 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…