Using “this” with jQuery Selectors

后端 未结 3 1522
余生分开走
余生分开走 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
      });      
    
    0 讨论(0)
  • 2020-12-14 17:02
    $(this).next("p").css("...")
    

    the "p" above is optional, if you just want the next non-whitespace node in the DOM.

    0 讨论(0)
  • 2020-12-14 17:11

    Try using:

    $(this).siblings('p').css()
    
    0 讨论(0)
提交回复
热议问题