+ 3

I need to change the color of the page when mouse cursor is on it. What should I do?

web

11th Sep 2018, 2:54 PM
Mohammad Mahdi Mehrani
Mohammad Mahdi Mehrani - avatar
4 Respostas
+ 8
This can be done using Events. //First you have to select the element(the thing whose color will change): var thing = document.getElementById("elements'ID"); //Then you add a little event in there thing.onmouseover = function() { thing.style.backgroundColor = "as you wish"; } //So you are done... Take a look at the lesson explaining it: https://www.sololearn.com/learn/JavaScript/2758/
11th Sep 2018, 3:00 PM
Ledio Deda
Ledio Deda - avatar
+ 3
thank you very much
11th Sep 2018, 3:02 PM
Mohammad Mahdi Mehrani
Mohammad Mahdi Mehrani - avatar
+ 3
Example ;D <!DOCTYPE html> <html> <head> <style> p:hover, h1:hover, a:hover { background-color: yellow; } </style> </head> <body> <h1>Welcome to My Homepage</h1> <div class="intro"> <h2 id="firstname">My name is Donald</h2> <p id="hometown">I live in Duckburg</p> <p>My <b>best</b> friend is Mickey</p> </div> <h2>Links:</h2> <p>Here are my favorite websites:</p> <a href="https://www.w3schools.com">w3schools.com</a> <a href="http://www.disney.com" target="_blank">disney.com</a> <a href="http://www.wikipedia.org" target="_top">wikipedia.org</a> <p><b>Note:</b> Mouse over paragraphs, headers, and links to see what is getting a style.</p> <p><b>Note:</b> For :hover to work for other than links in IE, a DOCTYPE must be declared.</p> </body> </html>
11th Sep 2018, 3:10 PM
DANIOALEKSANDro
DANIOALEKSANDro - avatar
+ 2
thanks
11th Sep 2018, 4:35 PM
Mohammad Mahdi Mehrani
Mohammad Mahdi Mehrani - avatar