Where am I going wrong in this? //http://javascript.about.com/library/bldom08.htm document.getElementsByClassName = function(cl) { var retnode = []; var myclass = new RegExp('\\b'+cl+'\\b'); var elem = this.getElementsByTagName('*'); for (var i = 0; i < elem.length; i++) { var classes = elem[i].className; if (myclass.test(classes)) retnode.push(elem[i]); } return retnode; }; function Toggle(item) { obj=document.getElementsByClassName(item); visible=(obj.style.display!="none") //Line: 151 key=document.getElementById("x" + item); if (visible) { obj.style.display="none"; key.innerHTML="[+]"; } else { obj.style.display="block"; key.innerHTML="[-]"; } } Code (markup): and <div ID="support" style="display:none; margin-left:2em"> <span class='forForum' style='display:none; font-weight: bold;'>[quote]</span> <span class='forForum' style='display:none; font-weight: bold;'>[b]</span> :<span class='forForum' style='display:none; font-weight: bold;'>[/b]</span><br />... Code (markup):
Can you send me the code you are calling this function with? Or the link to the page giving you this problem. It appears that the value you are pass the function is NOT an object that is known. It is possible that you are calling the function before the page is completely rendered?
Your problem is that your getElementsByClassName is returning an array & you're working with it as if it were an object/HTMLElement. obj=document.getElementsByClassName(item); obj = obj[0]; visible=(obj.style.display!="none") //Line: 151 Code (markup):