Select current element in jQuery

前端 未结 5 827
无人共我
无人共我 2020-12-08 00:30

I have HTML code like this :



         


        
5条回答
  •  春和景丽
    2020-12-08 00:57

    To select the sibling, you'd need something like:

    $(this).next();
    

    So, Shog9's comment is not correct. First of all, you'd need to name the variable "clicked" outside of the div click function, otherwise, it is lost after the click occurs.

    var clicked;
    
    $("div a").click(function(){
       clicked = $(this).next();
       // Do what you need to do to the newly defined click here
    });
    
    // But you can also access the "clicked" element here
    

提交回复
热议问题