jquery - Add css to class with style (url) find -
im looping through divs on specific page , url thats defined theme in 'style' attribute. if find url add css specific class. getting no errors, can take took wrong turn?
code:
if (top.location.pathname === '/news/') { $j("div").each(function() { if ($j(this).css('background-image') === 'http://daddykate-acc.daddykate.be/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png') { $j('.vc_gitem-zone').css('display', 'none'); } }); }
little ps: $j
required make code work (wp theme obligation)
edit: ok, used 'settimeout' function make function run after dom loaded. working fine now, thank input !
asking background-image
return somthing url("http://...")
, check fails here. regex
or indexof
:
if( top.location.pathname === '/news/' ) { $j("div").each(function() { if( $j(this).css('background-image').indexof('daddykate-acc.daddykate.be/wp-content/plugins/js_composer/assets/vc/vc_gitem_image.png') >= 0 ) { $j('.vc_gitem-zone').css('display', 'none'); } }); }
and hint, know can wrap code , use $
instead of $j
? reuse code on other pages.
you can ready state
of jquery:
$j(function($) { $("div").each(function() { /* ... */ }); });
or iife:
(function($) { $("div").each(function() { /* ... */ }); })($j)
Comments
Post a Comment