I am trying to make a button that toggles between making an img grayscale and normal. I need to find a way to properly target the button if it was clicked. I tried adding a class on click and then targeting that class. I also tried this.
$('.switch').on("click", function() {
if($(this).attr('data-click-state') == 1) {
$(this).attr('data-click-state', 0)
$(this).siblings('img').css("-webkit-filter", "grayscale(100%)");
} else {
$(this).attr('data-click-state', 1)
$(this).siblings('img').css("-webkit-filter", "none");
}
});
Why the button doesn't toggle between color and grayscale versions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…