Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用;这";使用jQuery选择器_Javascript_Jquery_Css Selectors - Fatal编程技术网

Javascript 使用;这";使用jQuery选择器

Javascript 使用;这";使用jQuery选择器,javascript,jquery,css-selectors,Javascript,Jquery,Css Selectors,我有一些HTML如下所示: <ul class="faq"> <li class="open"> <a class="question" href="">This is my question?</a> <p>Of course you can, it will be awesome. </p> </li> </ul> 来测试一下。看起来,兄弟选择器不

我有一些HTML如下所示:

<ul class="faq">
    <li class="open">
        <a class="question" href="">This is my question?</a>
        <p>Of course you can, it will be awesome. </p>
    </li>
</ul>
来测试一下。看起来,兄弟选择器不能像那样使用,因为我对jQuery完全陌生,所以我不知道如何实现这一点

$(this).next("p").css("...")
如果您只需要DOM中的下一个非空白节点,则上面的“p”是可选的。

尝试使用:

$(this).siblings('p').css()
我想在单击锚时使用jQuery显示或隐藏“p”标记

既然您提到要在单击锚定时切换“p”标记,我会:

  $("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
  });      

好极了,这是完美的(而且比毫无结果的谷歌搜索要快得多)。谢谢懒虫网很棒,不是吗?:)哦,请记住,如果你添加更多,它会对你的
  • 中的每个“p”标签产生影响。不是苦的吗?别担心,我的评论没有建设性。(5年后…)为了补偿你,Ben,我在大约6个月前注册了NSScreencasts,得到了很多;-)。啊,我一直想知道使用点击事件的jQuery版本是什么。谢谢嘿,谢谢,这让我不用再思考了!我最终选择了slideToggle()而不是show(),主要是因为我想让人们觉得我很酷
      $("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
      });