开发者

Most appropriate way to select first occurrence of a child element in jQuery

I have a list like so:

<ul id="topElement">
  <li></li>
  <li>
    <ul>
      <li>
        <ul>
          <li>
          </li>
        </ul>
      </li>
    </ul>
  <li>

Using jQuery, what is the best aka most efficient way to reference the first occurrence of a ul from #topElement.

That is to say, I do not want this...

$("#topElement ul") 

Which will return every ul element in 开发者_如何学运维the tree. I only want the first ul down.

Thanks,


I think that if you want the first "ul" you find inside the contents of the "ul" called "topElement", then you'd want this:

$('ul#topElement ul:first')


$("#topElement ul").first();


$("ul#topElement:first") 


$("#topElement > li > ul:first")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜