Hi, I've got some javascript code. It works perfectly in Firefox but not in Internet Explorer where I get a "Object Expected" error message on the line with the link. The funcion closes every div with the class name of "class" and opens a div with the id "id". Here is the code:
Function (I've got the function getElementsByClass in my common.js):
And here is the call, I've tried both these versions:Code:function toggle(id,class) { var a = getElementsByClass(class); for(var i=0;i<a.length;i++) { a[i].style.display='none'; } var b = document.getElementById(id); if(b.style.display == 'block') b.style.display = 'none'; else b.style.display = 'block'; }
The thing is that it works perfectly fine in Firefox but not in IE, a little bit strange, or perhaps notCode:<a href="javascript: toggle('divSubSub7', 'divSubSub');">SubSub7</a> <a href="#" onclick="toggle('divSubSub7', 'divSubSub'); return false">SubSub7</a>
The getElementsByClass function looks like:
When I tried now I got an error on the first line second character and they look like this:Code:function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)'); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; }
Anyone know what I'm doing wrong? Thanks in advance!Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Alfred




Reply With Quote

Bookmarks