/    Sign up×
Community /Pin to ProfileBookmark

Simple change element style Code no working in IE

Hi all,
I have the following code in my page but unfortunatelly it’s not working properly in IE6 and IE7.

HTML

[CODE]<div name=”cafe” id=”cafe1″ class=”elink”><a href=”#”>Cafe 1</a></div>
<div name=”cafe” id=”cafe2″ class=”elink”><a href=”#”>Cafe 2</a></div>
<div name=”cafe” id=”cafe3″ class=”elink”><a href=”#”>Cafe 3</a></div>[/CODE]

JAVASCRIPT

[CODE]function changeStyle(element){
[COLOR=”Red”]var e = document.getElementsByName(‘cafe’);
for(var i=0;i<e.length;i++){
e[i].style.backgroundColor = ‘#000000’;
}[/COLOR]
document.getElementById(element).style.backgroundColor = ‘#ffffff’;
}[/CODE]

Actually the lines colored in red don’t seem to work. The last line document.getElementById(element).style.backgroundColor = ‘#ffffff’; is ok.

Why is this happening? Can someone help please???

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorJan 12.2009 — Using getElementsByName on non-form-based elements is not guaranteed by the specs.
×

Success!

Help @ktsixit 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...