Jquery $(this) Child Selector

前端 未结 4 1695
情歌与酒
情歌与酒 2020-12-25 11:00

I\'m using this:

jQuery(\'.class1 a\').click( function() {
  if ($(\".class2\").is(\":hidden\")) {
    $(\".class2\").slideDown(\"slow\");
  } else {
    $(\         


        
4条回答
  •  眼角桃花
    2020-12-25 11:08

    In the click event "this" is the a tag that was clicked

    jQuery('.class1 a').click( function() {
       var divToSlide = $(this).parent().find(".class2");
       if (divToSlide.is(":hidden")) {
          divToSlide.slideDown("slow");
       } else {
          divToSlide.slideUp();
       }
    });
    

    There's multiple ways to get to the div though you could also use .siblings, .next etc

提交回复
热议问题