/    Sign up×
Community /Pin to ProfileBookmark

How to dynamically change the class name of all links on a document

Hi,

I want to dynamically change the className of all “a” tagNames on a document. How can I do it.

Thanks
Leonard

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJun 28.2005 — [CODE]

function ChangeClassName(){
as=document.getElementsByTagName('BODY')[0].getElementsByTagName(A);
for (i=0;i<as.length;i++){
as[i].className='MyClassName';
}
}

[/CODE]
Copy linkTweet thisAlerts:
@crh3675Jun 28.2005 — Now, why would there be more than 1 BODY tag???

<i>
</i>function ChangeClassName(){
var as=document.getElementsByTagName("A");
for (i=0;i&lt;as.length;i++){
as[i].className='MyClassName';
}
}
Copy linkTweet thisAlerts:
@leonard905authorJun 28.2005 — because the code resides on an oracle as portal where there are multiple portlets and each portlet has a body tag.
Copy linkTweet thisAlerts:
@acorbelliJun 28.2005 — because the code resides on an oracle as portal where there are multiple portlets and each portlet has a body tag.[/QUOTE]
multiple body tags on the same page, or within iframes on a page?
Copy linkTweet thisAlerts:
@CharlesJun 29.2005 — Another option:function changeLinks (className) {
var l, i = 0;
while (e = document.links[i++]) {l.className = className};
}
Copy linkTweet thisAlerts:
@google_archive1Jul 27.2005 — indexed JUL 27 2005 11:15:57
×

Success!

Help @leonard905 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 6.1,
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,
)...