I have the following code:
$('#main-n开发者_运维技巧av 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:
- exception thrown and not caught (in my jquery 1.4.4 file)
- 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();
});
});
精彩评论