Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Checking if next element exists

Is there a way to check if an next element exists? Check my code:

if($("#people .making-of .mask ul li.current").next("li") != null) {     alert("Exists"); } else {     alert("Dont exists"); } 

What am I doing wrong? Thanks a lot!

like image 245
Lucas Veiga Avatar asked Oct 06 '11 17:10

Lucas Veiga


People also ask

How can I get next sibling in jQuery?

jQuery next() Method The next() method returns the next sibling element of the selected element. Sibling elements are elements that share the same parent. The DOM tree: This method traverse forward along the next sibling of DOM elements.

How do you find if element with specific ID exists or not?

Approach 1: First, we will use document. getElementById() to get the ID and store the ID into a variable. Then compare the element (variable that store ID) with 'null' and identify whether the element exists or not.

Does not exist jQuery?

In jQuery, you don't need to be worried about checking the existence of any element. If element does not exists, jQuery will do nothing. jQuery provides length property for every element which returns 0 if element doesn't exists else length of the element.


1 Answers

Have you tried looking at .next('li').length?

like image 76
George Avatar answered Sep 20 '22 03:09

George