SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Location
    Brooklyn, NY
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setAttribute + IE 6

    this script updates an image on a page and resets the class name of a link. Works fine in Mozilla browser. However, the setAttribute method in the second function doesn't work in IE. Is there a known bug connected with this?

    Any ideas? Thanks in advance.

    var view;
    //update image
    function getView(view)
    {
    var source = view.getAttribute("href");
    var imgsrc = document.getElementById("view");
    imgsrc.setAttribute("src", source);
    setClass(view);
    }
    // update class names of links
    function setClass(view)
    {
    var arLinks = document.getElementsByTagName("a");
    var ct = (arLinks.length-1);
    for (var i=0; i<ct; i++)
    {
    arLinks[i].setAttribute("class", "inactive");
    }
    view.setAttribute("class", "active");
    }

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Try the following instead.

    arLinks[i].className = "inactive";

    view.className = "active";
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Feb 2007
    Location
    Brooklyn, NY
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that did it.

  4. #4
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason for this is that the serAttribute method is handled differently in different browers, if you user setAttribute('className', 'whatwhat') this will work in IE6, however not in FF, yet setAttribute('class', 'whatwhat') works in FF and not in IE6 for the the specific attricbute class="" you will have to either write a function to detect browser and use the relevant setAttribute mthod or use the code supplied... hope that helps explain a little
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net


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
  •