2

I have a code to apply every li's border-left-color to its background.

But I want to apply background-color when user :hover on li element.

And Is that possible fill background left to right with jquery as in this example? It is easy with CSS but I dont know how to do it with jquery.

Here is another solution about left to right background with box-shadow property.

$(document).ready(function(){
     $('.side-category ul li').each(function(){
     $(this).css("background", $(this).css("border-left-color"));
  })
});

1 Answer 1

3

Here is the function with hover in and hover out :

$('.side-category ul li').hover(
  function() {
    // on hover
    $(this).css("background", $(this).css("border-left-color"));
    $(this).css("box-shadow", "inset 0 100px 0 0 "+$(this).css("border-left-color"));
  }, function() {
    // on remove hover
    $(this).css("background", "#fff");
    $(this).css("box-shadow", "");
  }
);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, It worked very well :) Thank you for your help!

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.