/    Sign up×
Community /Pin to ProfileBookmark

Object expected

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):

[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’;
}[/CODE]

And here is the call, I’ve tried both these versions:

[CODE]<a href=”javascript: toggle(‘divSubSub7’, ‘divSubSub’);”>SubSub7</a>

<a href=”#” onclick=”toggle(‘divSubSub7’, ‘divSubSub’); return false”>SubSub7</a>[/CODE]

Anyone know what I’m doing wrong? Thanks in advance!

Alfred

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@yellabuffNov 21.2006 — class is a reserved word. Try using a different word.

function toggle(id,class1) {

var a = getElementsByClass(class1);
Copy linkTweet thisAlerts:
@AlfredNauthorNov 21.2006 — Ahh, thanks a lot, you saved my day! I've been trying to solve this way to long.
×

Success!

Help @AlfredN spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...