4

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");
  });
});
0

2 Answers 2

6

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");
});
Sign up to request clarification or add additional context in comments.

1 Comment

Show us html or make a fiddle on jsfiddle.com
3

It is a better practice to add/remove a class

$(document).ready(function(){
    $(".yuimenuitemlabel").hover(function(){
        $("a.yuimenubaritemlabel.sub").toggleClass('hoverclass');
    });
});

And use a class with

.hoverclass{
   background-color:red;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.