/    Sign up×
Community /Pin to ProfileBookmark

className change multiple function

hi, i want to call a function that changes the classname of most of the page by using getElement by id……

basically what i’ve got now is a script:

[CODE]

function closeAll(id){
if (document.getElementById(id).className ==’level3-click’){
document.getElementById(id).className =’level3′;
}
}

[/CODE]

and i want to call the function for all the id’s without having to call the function multiple times how would i do this???

cheers Jam

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JFeb 05.2006 — Something like this maybe?

[code=php]
function closeAll(){
obj=document.getElementsByTagName("DIV")

for(var i=0;i<obj.length;i++){

if(obj[i].className =='level3-click'){
obj[i].className ='level3';

}

}

}
[/code]
Copy linkTweet thisAlerts:
@jamauthorFeb 06.2006 — is there a way to do that by the id i only want to target some of the id's at a time.... maybe an if/else thing i unno can n e 1 help????
Copy linkTweet thisAlerts:
@jamauthorFeb 06.2006 — n e 1??????
Copy linkTweet thisAlerts:
@UltimaterFeb 06.2006 — Something like this?
<i>
</i>function closeAll(){
var i,l=arguments.length,e

for(i=0;i&lt;l;i++){
e=document.getElementById(arguments[i]);if(!e)continue
if(e.className=='level3-click')e.className ='level3';
}

}

The function's usage is quite easy -- just send the function as many arguments as you want and it will "close" each of the elements.
<i>
</i>closeAll("idnumber1","idnumber2","idnumber3","anotherElementsId")
Copy linkTweet thisAlerts:
@jamauthorFeb 06.2006 — thats xactli what i wanted cheers it seems so simple now cheers much...... Jam
×

Success!

Help @jam 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.18,
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,
)...