隐藏包含特定字符串的div [英] Hiding div that contains specific string

查看:82
本文介绍了隐藏包含特定字符串的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用此网站上建议的其他解决方案隐藏包含特定字符串的div,但是没有任何效果(很可能是由于我对jQuery的经验不足)

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)

我想完全隐藏(在此示例中)包含字符串'zynthesized'的所有div

I'd like to completely hide all divs that (in this example) contain the string 'zynthesized'

<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()

应该最接近我的需求,但是我没有运气.

Should be closest to what I need, but I've had no luck with it.

任何帮助都将是惊人的!

Any help would be amazing!

推荐答案

感谢帮助人员!事实证明该脚本正在运行,但是由于页面在滚动时会自动加载新的div,因此必须在页面加载后运行脚本.

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.

最终脚本看起来像

$(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!

这篇关于隐藏包含特定字符串的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆