jQuery: Checking if next element exists

后端 未结 7 847
庸人自扰
庸人自扰 2020-12-02 18:08

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         


        
7条回答
  •  难免孤独
    2020-12-02 18:57

    Use the length method in jQuery:

    if($(...).next().length > 0) {
        alert("Exists.")
    } else {
        alert("Doesn't exist!")
    }
    

提交回复
热议问题