how to judge an element's previous or next element exist with jquery?

前端 未结 4 1300
说谎
说谎 2020-12-10 02:14

suppose I have an

    :

4条回答
  •  无人及你
    2020-12-10 02:36

    You need to check the length property.

    if ($("li.test").next().length) {
      //has next 
    } else {
      //last elem
    }
    

    Keep in mind that jQuery usually returns itself so you can chain. Getting the length property of that object will give you the information

提交回复
热议问题