Using “this” with jQuery Selectors

后端 未结 3 1528
余生分开走
余生分开走 2020-12-14 16:38

I have some HTML that looks like this:

3条回答
  •  醉话见心
    2020-12-14 16:59

    I want to use jQuery to display or hide the 'p' tag when the anchor is clicked

    Since you mentioned that you'd like to toggle the 'p' tag when the anchor is clicked, I'd do:

      $("a.question").click(function (event) {
          $(this).siblings('p').show(); //toggle the p tags that are siblings to the clicked element
          event.preventDefault(); //stop the browser from following the link
      });      
    

提交回复
热议问题