Reputation: 10659
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?
Upvotes: 3
Views: 54
Reputation: 3315
This seems to fix it:
$('.sampleclass a > img').addClass("someotherclass");
Upvotes: 0
Reputation: 11741
$('.sampleclass a > img').each(function() {
$(this).addClass("someotherclass");
});
Upvotes: 0
Reputation: 9180
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");
Upvotes: 4