Get the first jquery element in a deep search and break traversal
Is it possible to force jquery find()
to only return the first matched element and not the childs of th开发者_JS百科at element. Something that would be called "nearest"...
There is closest. The only thing with this is that it propagates up the DOM.
if you want to find the first matched element use :first
eg:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
you would do:
$('ul').find('li:first');
or you could just use the >
in your selector to return ONLY the children:
$('ul > li');
will ONLY return li's which are a direct child of the UL
using them both together:
$('ul > li:first');
will return the FIRST li which is a DIRECT child of the UL.
something like this might do
$jqObj.find( '.dummy:eq(0)' )
This would return the first matched element.
精彩评论