简体   繁体   English

隐藏包含特定字符串的div

[英]Hiding div that contains specific string

I've been trying to hide divs that contain particular string using the other solutions suggested on this site, however none worked (most likely due to my inexperience with jQuery) 我一直在尝试使用此网站上建议的其他解决方案隐藏包含特定字符串的div,但是没有任何效果(很可能是由于我对jQuery的经验不足)

I'd like to completely hide all divs that (in this example) contain the string 'zynthesized' 我想完全隐藏(在此示例中)包含字符串“ 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> 

From what I've seen something like 从我所看到的

 $('.photos-wrapper:contains("zynthesized")').hide() 

Should be closest to what I need, but I've had no luck with it. 应该最接近我的需求,但是我没有运气。

Any help would be amazing! 任何帮助都将是惊人的!

Thanks for the help guys! 感谢您的帮助! Turns out that the script was working however as the page loaded new divs automatically when scrolling, the script had to be run after the page loaded them. 事实证明该脚本正在运行,但是由于页面在滚动时会自动加载新的div,因此必须在页面加载后运行脚本。

The final script looks like 最终脚本看起来像

$(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();
    }
});

Hopefully this helps anyone looking to do something similar! 希望这对希望做类似事情的人有所帮助!

You can simply use a regex. 您可以简单地使用正则表达式。

<script>
    var ptrn = /zynthesized/g;

    $( "div" ).each(function( index ) {
      if(ptrn.test($( this ).text())){
        $( this ).hide();
      }
    });
</script>

Here is simple snippet : jsfiddle.net/dariubs/hgbm3doa 这是简单的代码段: jsfiddle.net/dariubs/hgbm3doa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM