Reputation: 12847
I need to change the opacity of all buttons after clicking one (except the button that was clicked).
Here is HTML code:
<button data-target="Section1" class="metro-button">Button1</button>
<button data-target="Section2" class="metro-button">Button2</button>
<button data-target="Section3" class="metro-button">Button3</button>
And jQuery code:
$(".metro-button").click(function(){
var buttons = document.getElementsByClassName("metro-button");
for(i = 0 ; i < buttons.length ; i++) {
if ($(this).attr('data-target') != buttons[i].attr('data-target')) {
buttons[i].animate({"opacity" : 0.3});
}
}
});
What is the problem ?
Any ideas would be appreciated.
Upvotes: 0
Views: 93
Reputation: 74420
Could be a solution too, depending of your HTML structure:
$(".metro-button").click(function () {
$(this).animate({
"opacity": 1
}).siblings('.metro-button').animate({
"opacity": .3
})
});
Upvotes: 1