大佬教程收集整理的这篇文章主要介绍了如何使用jquery获取连续元素?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<div class="aclass"> <h1>This is heading one</h1> <p>This is paragraph one,this will be hidden automatically</p> <p>This is paragraph two,this will be hidden automatically</p> <p>This is paragraph three,this will be hidden automatically</p> <h1>This is heading two</h1> <p>This is paragraph four,this will be hidden automatically</p> <p>This is paragraph five,this will be hidden automatically</p> </div>
CSS
.aclass p {display:none;}
JS
$(document).ready(function(){ $('.aclass h1').click(function(){ $(this).next('p').toggle(); }); });
当点击h1标签时,此JS代码在h1标签之后切换单个p标签的显示.但是我需要切换连续p标签的显示(点击标题1时一到三个)
应该是什么jQuery代码呢?
这里是保存点击的代码:
$('.aclass h1').click(function(){ $(this).nextUntil('h1','p').toggle(); });
以上是大佬教程为你收集整理的如何使用jquery获取连续元素?全部内容,希望文章能够帮你解决如何使用jquery获取连续元素?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。