[英]Hiding div that contains specific string
我一直在尝试使用此网站上建议的其他解决方案隐藏包含特定字符串的div,但是没有任何效果(很可能是由于我对jQuery的经验不足)
我想完全隐藏(在此示例中)包含字符串“ zynthesized”的所有div
<div class="photos-wrapper" id="detailPhoto-977355202965894535_11842652"> <div class="pseudo"> <a href="#/user/11842652/">zynthesized</a> </div> <div class="image-wrapper"> <a href="#/detail/977355202965894535_11842652" class="lienPhotoGrid"><img src="https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e15/11195725_518243828313545_1133319712_n.jpg"></a></div> <div class="activites"> <span class="popular_picto ss-star "></span> <div class="album-relative detail-photo-album-977355202965894535_11842652" style="display: none;"> <input type="hidden" class="apalbumsPhoto" value="977355202965894535_11842652"> <input type="hidden" class="apalbumsPhoto-977355202965894535_11842652" value=""> </div> <span class="nb_comment_score">0</span> <span class="comment_picto ss-chat"></span> <span class="nb_like_score">4</span> <a href="#" class="like_picto_unselected likeAction ss-heart gridLike" id="like-977355202965894535_11842652"></a> </div> <div class="nouveau-commentaire"> <textarea id="comment-977355202965894535_11842652" class="textareaCommentaire" placeholder="Your comment"></textarea> <a href="#" class="commentAction ss-chat" id="postComment-977355202965894535_11842652"></a> <img src="http://static.iconosquare.com/images/loading.gif" class="commentLoading"> </div> </div>
从我所看到的
$('.photos-wrapper:contains("zynthesized")').hide()
应该最接近我的需求,但是我没有运气。
任何帮助都将是惊人的!
感谢您的帮助! 事实证明该脚本正在运行,但是由于页面在滚动时会自动加载新的div,因此必须在页面加载后运行脚本。
最终脚本看起来像
$(window).load(function(){
$(".photos-wrapper:contains('zynthesized')").hide();
});
$(window).on('scroll', function() {
var y_scroll_pos = window.pageYOffset;
var scroll_pos_test = 150;
if(y_scroll_pos > scroll_pos_test) {
$(".photos-wrapper:contains('zynthesized')").hide();
}
});
希望这对希望做类似事情的人有所帮助!
您可以简单地使用正则表达式。
<script>
var ptrn = /zynthesized/g;
$( "div" ).each(function( index ) {
if(ptrn.test($( this ).text())){
$( this ).hide();
}
});
</script>
这是简单的代码段: jsfiddle.net/dariubs/hgbm3doa
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.