script not working in IE 6

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J Weaver

    script not working in IE 6

    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.g etElementsByTag Name("DIV");
    elem.item(1).se tAttribute("sty le","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="turnRe d()">

  • Janwillem Borleffs

    #2
    Re: script not working in IE 6


    "J Weaver" <scruffdawg@yah 00.com> schreef in bericht
    news:pFdqb.3117 21$9l5.57447@pd 7tw2no...[color=blue]
    >
    > 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.
    >[/color]

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

    function turnRed(){
    var elem=document.g etElementsByTag Name("DIV");
    elem.item(0).st yle.color = "red";
    }


    JW



    Comment

    • David Dorward

      #3
      Re: script not working in IE 6

      J Weaver wrote:
      [color=blue]
      > 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.[/color]
      [color=blue]
      > elem.item(1).se tAttribute("sty le","color:red" );[/color]

      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/

      Comment

      • Svend Ezaki Tofte (DIKU)

        #4
        Re: script not working in IE 6

        On Wed, 5 Nov 2003, David Dorward wrote:
        [color=blue]
        > MSIE doesn't support setAttribute.[/color]

        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

        Comment

        Working...