var boardMembs = ["boardMembersName", "boardMembersName", "boardMembersName"]; function setupItems() // initiates from { for (var i=0; i< boardMembs.length; i++) { var currentID = document.getElementById(boardMembs[i]); if (currentID.addEventListener) // does the browser understand this command { currentID.addEventListener('click', expansion, false); // if so, do this } else { currentID.attachEvent('onclick',expansionIE); // if not, do this } } } function expansion() { var curTitle = this.getAttribute("title"); var getHiddenElement = this.nextSibling.nextSibling; if (curTitle == "inactive") { this.setAttribute("title", "active"); getHiddenElement.setAttribute("class", "boardMembBody active") } else { this.setAttribute("title", "inactive"); getHiddenElement.setAttribute("class", "boardMembBody inactive"); } } function expansionIE(e) { if (!e) // if not e, than set e { var e = windows.event; } if (!e.target) // if not e.target, than set e.target { e.target = e.srcElement; } var curTitle = e.srcElement.getAttribute("title"); // get title from html tag var getHiddenElement = e.srcElement.nextSibling.getAttribute("className"); // get class name if (getHiddenElement == "boardMembBody inactive") // does the class = "boardMembBody inactive" { e.srcElement.nextSibling.setAttribute("className", "boardMembBody active"); // if so change to active } else { e.srcElement.nextSibling.setAttribute("className", "boardMembBody inactive"); // if not than must be active, so change to inactive } }