Reputation: 14783
i have a few buttons:
<button class="image1-button"><img src="images/button_unselected.png"></button>
<button class="image1-button"><img src="images/button_unselected.png"></button>
<button class="image1-button"><img src="images/button_unselected.png"></button>
<button class="image1-button"><img src="images/button_unselected.png"></button>
when i press one of them the following happen:
$(".image1-button").click(function(){
$(this).find("img").attr("src", "images/button_selected.png");
});
how can i say that the other, means not(this) get the src "images/button_unselected" that always only the currently pressed button has "button_selected"
thank you!
Upvotes: 0
Views: 60
Reputation: 3881
$(".image1-button").click(function(){
$(this).find("img").attr("src", "images/button_selected.png")
$(this).siblings().find("img").attr("src", "images/button_unselected.png")
});
Upvotes: 0
Reputation: 3643
Like this:
$(".image1-button").click(function(){
//Reset all
$(".image1-button").find("img").attr("src", "images/button_unselected.png");
//mark current
$(this).find("img").attr("src", "images/button_selected.png");
});
Upvotes: 2