Questions And Answers

More Tutorials

Jquery Get next element

To get the next element you can use the .next() method.

 <li class="anna">Anna</li>

If you are standing on the "Anna" element and you want to get the next element, "Paul", the .next() method will allow you to do that.

// "Paul" now has green text
$(".anna").next().css("color", "green");

The method takes an optional selector argument, which can be used if the next element must be a certain kind of element.

// Next element is a "li", "Paul" now has green text
$(".anna").next("li").css("color", "green");

If the next element is not of the type selector then an empty set is returned, and the modifications will not do anything.

// Next element is not a ".mark", nothing will be done in this case
$(".anna").next(".mark").css("color", "green");


In this page (written and validated by ) you learned about Jquery Get next element . What's Next? If you are interested in completing Jquery tutorial, your next topic will be learning about: Jquery Get previous element.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.