开发者

jQuery prev() and next()

I am using jQuery. I have HTML code which looks like this:

<ul>
    <li>123</li>
    <li id="hello">456</li>
</ul>
<ul>
    <li>78开发者_开发问答9</li>
</ul>

I want, with jQuery, to get the li element after #hello (the 789 element). I tried with $('#hello').next(), it does not work.

How do I do?


$('#hello').parent().next().children();
  • the parent()[docs] method to go up to the <ul> element

  • the next()[docs] method to go to the next <ul> element

  • the children()[docs] method to get the nested <li> element


try something like

$('#hello').parent().next().children().eq(0)

http://api.jquery.com/category/traversing/tree-traversal/ might be useful

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜