---
title: "Change background color on mouseover and remove it after mouseout"  
description: "Change background color on mouseover and remove it after mouseout"  
author: "Anonymous User"  
published: 2018-05-27  
updated: 2018-05-27  
canonical: https://www.mindstick.com/forum/34495/change-background-color-on-mouseover-and-remove-it-after-mouseout  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# Change background color on mouseover and remove it after mouseout

I want to change the [background color](https://www.mindstick.com/forum/12937/how-to-style-togglebutton-so-that-the-background-color-is-white) on [mouse hover](https://answers.mindstick.com/qa/30760/how-to-change-div-color-on-mouse-hover-using-css) .This [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why) but I think this is not the [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) code

```
<script type="text/javascript">
    $(document).ready(function() {
        $('.test').bind("mouseover", function(){
            var color = $(this).css("background-color");

            $(this).css("background", "#380606");

            $(this).bind("mouseout", function(){
                $(this).css("background", color);
            })
        })
    })
</script>
```

can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) some other solution?

## Replies

### Reply by Anonymous User

try this code

```
<script>
$(document).ready(function(){
    $(".test").hover(function(){
        $(this).css("background-color", "yellow");
        }, function(){
        $(this).css("background-color", "pink");
    });
});
</script>
```

\


---

Original Source: https://www.mindstick.com/forum/34495/change-background-color-on-mouseover-and-remove-it-after-mouseout

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
