Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    setAttribute() and IE6

    Having some issues with setAttribute() and IE6, works in other browsers just being illusive in IE6.

    Any help here would be great.

    Currently using IETester v0.4.6.

    Stylez.

    Code:
    <div id="Element">Element</div>
    
    <script>
        document.getElementById("Element").setAttribute('onclick', 'alert("!")');
    </script>
    Last edited by ManyStylez; 12-10-2010 at 05:52 PM.

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Never use setAttribute when direct assignment will work:

    document.getElementById("Element").onclick = function(){ alert("!"); };

  • Users who have thanked Logic Ali for this post:

    ManyStylez (12-10-2010)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for that tip

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,395
    Thanks
    13
    Thanked 353 Times in 349 Posts
    PS. Element is the name of a DOM interface object. and because IE writes all IDs and names in the global scope, you can get name collision.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •