Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  61] [ 7]  / answers: 1 / hits: 32467  / 12 Years ago, mon, april 23, 2012, 12:00:00

I have written the following code:



$(document).ready(function () {
$(#rade_img_map_1335199662212).hover(function () {
$(li#rs1).addClass(active); //Add the active class to the area is hovered
}, function () {
$(li#rs1).addClass(not-active);
});
});


The problem is it doesnt seem to toggle the class on hover?



But how can i get it so that the class toggles based on hover and non-hover..?


More From » jquery

 Answers
18

Do not add a different class on hover-out just remove the active class



$(document).ready(function(){

$(#rade_img_map_1335199662212).hover(function(){

$(li#rs1).addClass(active); //Add the active class to the area is hovered
}, function () {
$(li#rs1).removeClass(active);
});

});


or if all elements are inactive at first you could use a single function and the toggleClass() method



$(document).ready(function(){

$(#rade_img_map_1335199662212).hover(function(){
$(li#rs1).toggleClass(active); //Toggle the active class to the area is hovered
});

});

[#86040] Sunday, April 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
acaciac

Total Points: 317
Total Questions: 117
Total Answers: 128

Location: France
Member since Thu, Oct 27, 2022
1 Year ago
;