Results 1 to 3 of 3

Thread: IE: Loop applies last value to all elements?

  1. #1
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Question IE: Loop applies last value to all elements?

    This is an IE specific script issue, no other browsers can see the script (conditional comments). I'm trying to fix a very miscellaneous problem with IE (imagine that?) though in the simplest of terms IE 6/7 is not seeing JavaScript related attributes on elements (e.g. onmouseover, onblur). I corrected a similar issue where IE was no applying CSS class attributes (IE is just outright having issues with attributes).

    So any way I'm trying to re-apply the attributes without having to muck up my XHTML code with anything intended for far outdated but people-are-still-using-it browsers. The problem is that somehow (and I've encountered this before though too far back to remember how I got it working) is that the last onmouseover attribute is applied to all of the elements where I find the onmouseover attribute (though IE does not trigger). I can apply this almost as desired only every onmouseover event will only trigger the last script versus their respective script. I'm pretty upset at myself for not remembering how I fixed this in the past. What am I forgetting here?

    - John


    function ie_fix_events(t)
    {
    if (document.getElementById('body').currentStyle.scrollbarBaseColor)
    {
    if (t)
    {
    var e = document.getElementById(t).all;
    for (var i = 0; i < e.length; i++)
    {
    if (e[i].getAttribute('onmouseover'))
    {
    var a = e[i].getAttribute('onmouseover');
    e[i].attachEvent('onmouseover', function() {eval(a);});
    }
    }
    }
    }
    }

  2. #2
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Apparently there is a jQuery answer to this problem however I'm not using jQuery nor am I going to implement it just to fix this problem. Hopefully someone with a bit more insight in to this will have a better idea of what I'm talking about however...

    http://jquery-howto.blogspot.com/200...sertedetc.html

  3. #3
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    So I resolved the issue by eventually finding one of my own blog posts on how I resolved it.

    The answer is to create a second function which you call. I use alert to make sure I'm applying the correct code. Why I can't apply the event listeners inside of the first function I still don't really understand but creating a separate function is how I was able to conquer IE's face.

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
  •