Javascript 使用;这";使用jQuery选择器
我有一些HTML如下所示: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> 来测试一下。看起来,兄弟选择器不
<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
});
好极了,这是完美的(而且比毫无结果的谷歌搜索要快得多)。谢谢懒虫网很棒,不是吗?:)哦,请记住,如果你添加更多,它会对你的
$("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
});