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:
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.