简体   繁体   中英

jQuery IE6 and 7 error

I have the following code:

$('#main-nav a').mouseover(function() {
    var name = $(this).attr("rel");
    $("#subnav ul." + name).show();
})

Basically the code just gets the value of the rel attribute of a link when it is hovered over and then makes any ul with a class of the same value appear.

This code works fine in any other browser apart from IE6 and 7 which gives me the following errors:

  1. exception thrown and not caught (in my jquery 1.4.4 file)
  2. object doesn't support this property or method (in my jquery script that iv wrote)

It is something to do with the fact that iv used a variable in my selector, if i dont use a variable I don't get these errors.

The thing is though I need to put the variable in there in order for it to work, does anyone know of a better way to do this that won't cause these errors?

Thanks

As far as I can tell, '#main-nav a' returns a collection of <a> objects. Have you tried iterating the result with each ?

$.each($('#main-nav a'), function (index, element) {
    element.mouseover(function() { 
        var name = $(this).attr("rel"); 
        $("#subnav ul." + name).show(); 
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM