Javascript 在具有类的元素中隐藏元素
我想将Javascript 在具有类的元素中隐藏元素,javascript,jquery,comments,reply,Javascript,Jquery,Comments,Reply,我想将隐藏在中,如果它不在里面,就显示出来。希望你能帮我做这个把戏。下面是代码的样子 <ol class="comment-list"> <li class="comment"> <div id="comment-n"> <p>This is a comment</p> </div> <ul class="children">
隐藏在
中,如果它不在里面,就显示出来。希望你能帮我做这个把戏。下面是代码的样子
<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>
这是一个评论
-
这是对一条评论的回复。这里可以看到星级。我不想在回复评论时显示它
写一个回复或评论
您的电子邮件地址将不会发布
姓名
电子邮件
网站
评论
这应该可以做到:
$('.comment-list .crfp-field').hide();
您可以使用CSS,无需JS:
ol.comment-list p.crfp-field {
display: none;
}
如果
p.crfp-field
元素不在ol
内,则上述规则将不适用,元素将显示为正常。您可以通过以下方式实现:
$(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
});
它不起作用了。我把它放在标记
$('.comment list.crfp field').hide()之前;
没问题,很乐意帮忙。干杯!你是救命恩人:)它不起作用。可能它与插件的脚本有冲突。谢谢你!css技巧做到了这一点。