I'm currently working on adding a flip effect to multiple tiles whenever a user clicks on them as part of building a dashboard-style webpage. I am having trouble making the click event work for all tiles with the same class name.
Even though all the tiles have the same class name, they are placed under different "box" divs. The issue I am facing is that the jQuery click event only works for the last tile added, while the others remain static. I have been trying to find a solution to this problem without success. Here is the latest version of the click event code:
var i = 0,
abbrs = document.getElementsByClassName("tile"),
len = abbrs.length;
function addEvent(abbr) {
abbr.addEventListener("click", function(event) {
$(this).toggleClass("flip");
})
}
for (i; i < len; i++){
addEvent(abbrs[i]);
}
I am unsure where the root cause of the problem lies and would appreciate any help or suggestions.