web-profile

jQuery .next()

jQuery .next() gets the immediately following sibling of each element in the set of matched elements; Also check jQuery .prev();

js:

$('.target').next()
    .css('background-color', 'yellow')
    .append(' <span class="label label-info">next after .target</span>');


$('li').next('.target')
    .css('background-color', 'yellow')
    .append(' <span class="label">next with .target class</span>');

html:

<ul>
<li>list item
<ul>
<li>list item</li>
<li class="target">list item with target class</li>
<li>list item</li>
<li>list item</li>
</ul>
</li>
<li>list item</li>
<li class="target">list item with target class</li>
<li>list item</li>
<li>list item</li>
</ul>​

Leave a Reply

Your email address will not be published. Required fields are marked *