I don’t understand why my code doesn’t work.
I create dynamically groups of three buttons: the first button of the group has id 1, the second 101 and the third 201; buttons of the second group will be named respectively 2, 102 and 202, and so on.
If I want to delete all the three buttons by clicking the last one it works. This is what I set in the onclick event :
butt.onclick = function() {
removeElement(this.id);
removeElement(this.id-100);
removeElement(this.id-200);
}
But if I want to delete all the three buttons by clicking the middle one with this onclick event:
butt.onclick = function() {
removeElement(this.id+100);
removeElement(this.id);
removeElement(this.id-100);
}
it eliminates only buttons 1 and 101 but not 201.
It seems like it doesn’t like the “this.id+100” value. What’s the reason?
Thanks in advance.
Your mixing strings with numbers … and using the
+with a string concatenates tryYou use
parseInt()to convert strings to numbers in JavaScript