SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    eez
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Should I use setAttribute or not? Confused...

    Hi!

    I am very confused here... have heard that get/setAttribute are not water-proof... but have also heard that the .className method isn't either water-proof (I need it to work with many attribute names not just class).

    Need an expert's advice here.

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    In my knowledge get/setAttribute will work on almost everything except when you are trying to register any events. if you try to set any events dynamically using setAttribute method; for example, an onclick event to any element, it won't work in IE, but it will work on other browser like firefox, opera. IE uses attachEvent instead, which is for IE only. You can do the following to set up an onclick event instead of using setAttribute.

    Code:
    myObject.onclick = new Function( "return doSomething(param1, param2, ...) ;") ;
    
    function doSomething(param1, param2, ...)
    {
       //do whatever u want in here
    }
    The above worked for me in IE, firefox and opera. hope that helps.
    With Regards
    Pman
    http://www.pmansLab.com

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    eez
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


Bookmarks

Posting Permissions

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