jQuery closest class selector

后端 未结 6 616
野的像风
野的像风 2021-01-01 10:19
Click me
Information
6条回答
  •  情书的邮戳
    2021-01-01 10:57

    Yes, There are many method avaiable in Jquery to find closest of the DOM element

    $('.Level1').click(function(){
       $(this).next('.Level3').fadeToggle();
    });
    $('.Level2').click(function(){
       $(this).closest('.wrap').find('.Level3').fadeToggle();
    
    });
    $('.Level4').click(function(){
        $(this).parent().find('.Level3').fadeToggle(); 
    });
    
    $('.Level5').click(function(){
        $(this).siblings('.Level3').fadeToggle();
    });
    .level{background:Red;width:200px;height:40px;}
    .Level3{background:blue;width:300px;height:50px;}
    
    
    Click me()sing next)
    Information
    Click me(Using closest)
    Information
    Click me(Usingh Parent)
    Information
    Click me(Using Sibiling)
    Information

提交回复
热议问题