Change Background color of a web page using onmouseover property


The onmouseover property allows you set a script when the mouse pointer is moved onto an element. To change the background color, use the HTML DOM backgroundColor property.

Let us see an example to implement the onmouseover property and change the background color −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>Heading Two</h2>
   <a onmouseover="document.body.style.backgroundColor ='orange'">Hover over me to change the background color.</a><br>
</body>
</html>

Output

Now hover over the text to change the background color of the web page −

Updated on: 12-Jun-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements