By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,718 Members | 1,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,718 IT Pros & Developers. It's quick & easy.

script not working in IE 6

P: n/a
Hi

I'm very new to web scripting. Can someone tell me why this snippet
will work as expected in Mozilla 1.4 but not IE 6.0? I thought this
script should work in any browser compatible with W3C DOM. Any help is
greatly appreciated.

<script>

function turnRed(){
var elem=document.getElementsByTagName("DIV");
elem.item(1).setAttribute("style","color:red");
}

</script>

<DIV ID="div1">Div #1</DIV>
<DIV ID="div2">Div #2</DIV>
<DIV ID="div3">Div #3</DIV>
<INPUT TYPE="button" VALUE="Turn #2 Red" onclick="turnRed()">

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"J Weaver" <sc********@yah00.com> schreef in bericht
news:pFdqb.311721$9l5.57447@pd7tw2no...

I'm very new to web scripting. Can someone tell me why this snippet
will work as expected in Mozilla 1.4 but not IE 6.0? I thought this
script should work in any browser compatible with W3C DOM. Any help is
greatly appreciated.


IE is not fully compliant. The following will work in both IE and Mozilla:

function turnRed(){
var elem=document.getElementsByTagName("DIV");
elem.item(0).style.color = "red";
}
JW

Jul 20 '05 #2

P: n/a
J Weaver wrote:
I'm very new to web scripting. Can someone tell me why this snippet
will work as expected in Mozilla 1.4 but not IE 6.0? I thought this
script should work in any browser compatible with W3C DOM. elem.item(1).setAttribute("style","color:red");


MSIE doesn't support setAttribute.

I won't swear to it, but I think setAttribute is DOM2, and MSIE only
supports DOM1.

--
David Dorward http://dorward.me.uk/
Jul 20 '05 #3

P: n/a
On Wed, 5 Nov 2003, David Dorward wrote:
MSIE doesn't support setAttribute.


MSIE "supports" it. But it's just so bug ridden it might as well not have.
The difference between no support, and crappy support, is that the latter
is much more dangerous.

Regards,
Svend
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.