I use the following function to bind all members of a certain class to a function that changes the current page. Heres the function:
function _bind_menu_items() {
var menuItems = fja.getElementsByClass("menuItem"),
index,
elementID,
divIdToBind;
for (index in menuItems) {
elementID = menuItems[index].id;
divIdToBind = elementID.replace("Item", "");
menuItems[index].onclick = function() {
fja.menu.changeActivePage(divIdToBind);
};
}
}
I’ve checked that everything works as expected down to the actual assignment of the onclick property. The error I’m getting is that every div belonging to the menuItem class seems to call the same onclick function... as if the divIdToBind string is the exact same for every onclick that is assigned... How can I fix this?