3
I need to locate a class called uk-slideshow
inside the HTML, after locating, I need to check inside the uk-slideshow
image, if you have, add a class in this img. PS: It’s more of an image.
The structure of HTML that’s how it is:
<div>
<ul class="uk-slideshow">
<li>
imagem
</li>
<li>
imagem
</li>
</ul>
With jQuery is much more practical and would do this way:
jQuery(document).ready(function($){
$('.uk-slideshow > li img').each(function(){
$(this).addClass("via-img-banner");
});
})
But I need to do this in JS native. I tried to do it this way:
<script>var slide = document.getElementsByClassName("uk-slideshow").getElementsByTagName("img");slide.add("via-img-no-lazy");</script>
How could I do that? I’ll apply that to the Wordpress, I know that the jQuery would be the best option, but due to using a plugin, I will run this code directly from head.
If you want to get all images pq does not use the direct selector in css
.uk-slideshow > li > img
, I didn’t understand the need to add one more class– hugocsl
I am configuring a plugin Lazy Load, in the plugin, I will insert this class so that the image is ignored.
– Wendell Mosquini Pozzatti
Careful that this selector
.uk-slideshow > li img
is wrong, will not find anything, because between the div and the<li>
there is a<ul>
. By using the sign>
you’re saying that the<li>
are direct daughters of the div, which is not true. ;)– Sam