jquery - how to combine functions for elements with consecutive IDs -
sorry if title confusing, not think of better. basically, want straight forward. code
jquery('.button1').click(function() { jquery(".box1").slideup(); jquery(this).remove(); }); jquery('.button2').click(function() { jquery(".box2").slideup(); jquery(this).remove(); }); jquery('.button3').click(function() { jquery(".box3").slideup(); jquery(this).remove(); }); and on.... that's pretty mess when have more boxes. there way can combine them , let jquery id numbers?
you can set class name buttons (e.g. "buttons") , use id:
<button id="button1" class="buttons">delete</button> then, can make trick number id:
$(".buttons").on("click", function() { var n = this.id.replace("button", ""); $(".box" + n).slideup(); $(this).remove(); });
Comments
Post a Comment