Jquery 如何添加类
XYZ XYZ XYZ XYZ XYZ 现在我想在p上添加一个类,它就在p之后,我想隐藏它。然后在h4上单击“想要显示”按钮。您可以使用Jquery 如何添加类,jquery,html,Jquery,Html,XYZ XYZ XYZ XYZ XYZ 现在我想在p上添加一个类,它就在p之后,我想隐藏它。然后在h4上单击“想要显示”按钮。您可以使用 <div class="post-content"> <p>XYZ</p> <h4></h4> <p>XYZ</p> <h4></h4> <p>XYZ</p>
<div class="post-content">
<p>XYZ</p>
<h4></h4>
<p>XYZ</p>
<h4></h4>
<p>XYZ</p>
<h4></h4>
<p>XYZ</p>
<h4></h4>
<p>XYZ</p>
<h4></h4>
</div>
添加/删除类的步骤
如果我理解你的问题,我会选择jquery:
$("#MyElement").addClass(classname);
$("#MyElement").removeClass([classname]);
$("#MyElement").toggleClass(classname);
$(函数(){
$('.post content p').hide().next('h4')。单击(函数(){$(this.prev().show()});
});
XYZ单击我
这其中有什么问题?或者这是一个“请为我写下我的整个脚本”的“问题”?请添加更多细节。明确的问题得到明确的答案。+1,在问题接近之前需要提供更多的信息。实际上1)我想在p标签上添加一个类,它刚好位于h4标签之后。
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>
$(function(){
$('.post-content p').hide().next('h4').click(function(){ $(this).prev().show() });
});
</script>
<div class="post-content">
<p>XYZ</p><h4>Click me</h4>
</div>