I am trying to do something with each hyperlinked image within a div with class of sampleclass:
<div class="sampleclass">
<a href="#">text hyperlink</a> <!-- don't touch this -->
<a href="#"><img src="image.jpg"></a> <!-- only touch this -->
</div>
Here is what I have:
$('.sampleclass a > img').(function() {
$(this).addClass("someotherclass");
});
This doesn't seem to work. Any suggestions?
Something is missing here.
$('.sampleclass a > img').(function() {
$(this).addClass("someotherclass");
});
This:
$('.sampleclass a > img').each(function() {
$(this).addClass("someotherclass");
});
Note that if you're only doing simple things like that, you can also omit the call to each .each().
$('.sampleclass a > img').addClass("someotherclass");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With