Wednesday, 28 August 2013

Can't get jQuery .each() to work

Can't get jQuery .each() to work

I have this HTML code in 3 sections of my page:
<div class="pjesmarrje">
<a href="#"
onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),'facebook-share-dialog','width=626,height=436');
return false;">
<div></div>
<span>Kliko këtu për pjesëmarrje</span>
</a>
</div>
And, I am trying to change the background image of the div inside when its
clicked. I got this jQuery code:
$(document).ready(function() {
$(".pjesmarrje").click(function() {
$(".pjesmarrje div").css("background-image",
"url(images/mumanin_s2.png)");
});
});
When I click one of the elements, all the others get their background
images changed too. I don't want that to happen, I want the bg image to be
changed only when that particular element is clicked. I tried to use the
.each() function, but it didn't work.
Any help is appreciated. Thanks.

No comments:

Post a Comment