在具有类的元素中隐藏元素
Hide an element inside an element with a class
我想把<p class="crfp-field">
隐藏在<ol class="comment-list">
里面,如果它不在里面,就把它显示出来。希望你能帮我做这个把戏。以下是代码的样子
<ol class="comment-list">
<li class="comment">
<div id="comment-n">
<p>This is a comment</p>
</div>
<ul class="children">
<li class="comment">
<div id="comment-n">
<p>This is a reply to a comment. Star rating is visible here. I don’t want to display it when I am replying to a comment.</p>
</div>
<div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title">Write a Reply or Comment <small><a class="btn" rel="nofollow" id="cancel-comment-reply-link" href="" style="">Cancel Reply</a></small></h3>
<form action="http://../wp-comments-post.php" method="post" id="commentform" class="comment-form">
<p class="comment-notes">Your email address will not be published.</p>
<p class="comment-form-author">Name<input id="author" name="author" type="text"></p>
<p class="comment-form-email">Email<input id="email" name="email" type="text"></p>
<p class="comment-form-url">Website<input id="url" name="url" type="text"></p>
<!-- CRFP Fields: Start -->
<p class="crfp-field">
<!-- CRFP Stuff -->
</p>
<!-- CRFP Fields: End -->
<p class="comment-form-comment">Comment<textarea id="comment" name="comment"></textarea></p>
<input id="submit-new" value="Post Comment" type="submit">
</form>
</div>
</li><!-- #comment-## -->
</ul><!-- .children -->
</li><!-- #comment-## -->
</ol>
您可以使用CSS,不需要JS:
ol.comment-list p.crfp-field {
display: none;
}
如果p.crfp-field
元素不在ol
内部,则将不应用上述规则,并且该元素将正常显示。
这应该做到:
$('.comment-list .crfp-field').hide();
您可以通过以下方式实现:
$(document).ready(function(){
$("p.crfp-field").show(); //show all p tag with class crfp-field
$("ol.comment-list p.crfp-field").hide(); //hide the needed ones
});
相关文章:
- 切换一个元素并将其余元素隐藏在同一包装类下
- CSS 动画在元素隐藏时暂停
- 检查元素是否可见,父元素隐藏在DOM中
- 粘性导航元素 - 隐藏然后显示
- show() 在元素隐藏时不起作用
- 通过可见性隐藏和显示元素:隐藏/可见
- 如何从检查页面元素隐藏Blogger中的javascript代码
- 基于页面元素隐藏部分html代码
- 使用jQuery和select元素隐藏动态类
- Jquery Div元素隐藏
- 当指针在父元素上时,Boostrap工具提示会在父元素隐藏之前触发悬停事件
- 聚焦元素隐藏在固定菜单后面
- 将jQuery中的元素隐藏在表中
- 元素.隐藏变量可移植性
- 如何使一个元素隐藏在向下滚动的wordpress
- 当父元素隐藏时,如何使用jquery show()
- 高度:自动计算错误,如果元素隐藏时dom加载,然后显示
- Javascript元素隐藏不起作用
- 使元素隐藏后直接显示完成jquery
- HTML表单元素隐藏的onload javascript