Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Jquery .css on unhover

Tags:

jquery

How to remove .css("background","red"); from (A.yuimenubaritemlabel.sub) element after unhovering .yuimenuitemlabel element ?

$(document).ready(function(){
  $(".yuimenuitemlabel").mouseover(function(){
   $("A.yuimenubaritemlabel.sub").css("background","red");
  });
});
like image 957
user1876234 Avatar asked Jan 14 '23 14:01

user1876234


1 Answers

You need to reset the css property on mouse leave.

$(".yuimenuitemlabel").mouseover(function(){
   $("A.yuimenubaritemlabel.sub").css("background","red");
}).mouseleave(function(){
     $("A.yuimenubaritemlabel.sub").css("background","");
});

Use hover function if you have do do many things you can use hover.

$(".yuimenuitemlabel").hover(function(){
   $("A.yuimenubaritemlabel.sub").css("background","red");
}, function(){
     $("A.yuimenubaritemlabel.sub").css("background","");
});

Use hover function assuming you just need to change the css. You can make two class one is sub and other is newsub.

$(".yuimenuitemlabel").hover(function(){
     $("A.yuimenubaritemlabel.sub").toggleClass("newsub");
});
like image 139
Adil Avatar answered Jan 24 '23 16:01

Adil