开发者

jQuery prev() and next()

开发者 https://www.devze.com 2023-02-12 14:27 出处:网络
I am using jQuery. I have HTML code which looks like this: <ul> <li>123</li> <li id=\"hello\">456</li>

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

精彩评论

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

关注公众号