2

I'm trying to change the element , and it just wouldnt work. Can anyone point out what am i doing wrong?

$(document).ready(function(){
  $(".navbar").hover(function(){
    $(this).css({'background-color': '#ffffff'});
 });
});
5
  • 2
    your code should work .. are you sure you include jquery before this code?? Commented Dec 8, 2015 at 16:09
  • Review the browser console and include the errors that you find there. Commented Dec 8, 2015 at 16:10
  • Do you get any errors in the console? Write this code after you have included jQuery. Commented Dec 8, 2015 at 16:10
  • @Noah Java console? :P Commented Dec 8, 2015 at 16:10
  • Thx guys i was just plain stupid. Commented Dec 8, 2015 at 19:43

2 Answers 2

2

Hover function in jquery needs two functions, the handleIn function as the first parameter and the handleOut function.

$(document).ready(function(){
  $(".navbar").hover(function(){
    $(this).css({'background-color': 'yellow'});
 },
 function(){
    $(this).css({'background-color': 'white'});
 });
});
Sign up to request clarification or add additional context in comments.

Comments

0

If you inspect using firebug, I guess you will that background is applied.

navbar element should have chlid "LI" element so you can add color to it by simply changing

$(document).ready(function(){
  $(".navbar li").hover(function(){
    $(this).css({'background-color': '#ffffff'});
 });
});

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.