0
如果背景是特定圖像,我正在嘗試向div(vc_gitem-animated-block)添加一個類。基本上,如果我的div有背景的特定圖像(vc_gitem_image.png),我想隱藏父div。如何將類添加到div如果背景圖像等於特定圖像
如果其他div有不同的背景,例如(blog-fpo.png),我需要父div沒有添加類,也不要隱藏它的父類。
我有這樣的代碼在我的網頁:
<style>
.hide{
display:none;
}
.show{
display:block;
}
</style>
<div class="vc_gitem-animated-block">
<div class="vc_gitem-zone vc_gitem-zone-a vc_gitem-is-link" style="background-image: url('http://savagebrands17.wpengine.com/wp-content/uploads/2016/12/blog-fpo.jpg') !important;">
<a href="http://savagebrands17.wpengine.com/join-savage-at-conscious-capitalism-2017-%c2%89uo-pitfalls-on-the-path-to-purpose-presentation/" title="Join Savage at Conscious Capitalism 2017 – 「Pitfalls on the Path to Purpose」 Presentation" class="vc_gitem-link vc-zone-link"></a>
<img src="https://savagebrands17.wpengine.com/wp-content/uploads/2016/12/blog-fpo.jpg" class="vc_gitem-zone-img" alt="">
<div class="vc_gitem-zone-mini">
</div>
</div>
</div>
<p> </p>
<div class="vc_gitem-animated-block">
<div class="vc_gitem-zone vc_gitem-zone-a vc_gitem-is-link" style="background-image: url('https://savagebrands17.wpengine.com/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png') !important;">
<a href="http://savagebrands17.wpengine.com/celebrating-client-work-savage-brands-honored-with-iabc-bronze-quill-awards-2/" title="Celebrating Client Work! Savage Brands Honored with IABC Bronze Quill Awards" class="vc_gitem-link vc-zone-link"></a>
<img src="https://savagebrands17.wpengine.com/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png" class="vc_gitem-zone-img" alt="">
<div class="vc_gitem-zone-mini">
</div>
</div>
</div>
這裏是我的腳本:
<script>
jQuery(function(){ /* to make sure the script runs after page load */
if (jQuery('.vc_gitem-zone.vc_gitem-zone-a.vc_gitem-is-link').css('background-image') === 'url(https://savagebrands17.wpengine.com/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png) !important;') {
jQuery(this).find('.vc_gitem-animated-block').addClass('hide');
}
});//END $function
我忘了提,有頁面上的其他div的,也將有一個名爲「vc_gitem動畫塊」父。這是否只將該類添加到具有該特定背景的類中?我還沒有嘗試過。 – gdeleon101
是的,這段代碼隱藏了我所有的div。我只需要具有指定背景圖像的人隱藏。有沒有辦法讓其他div不隱藏? – gdeleon101
請給出您使用的示例代碼。 – selvarajmas