I’m just messing around learning about JavaScript and I wanted to change the color of my background by resting my mouse over a link. Really I just want to learn about onMouseOver. I have:
<a href="http://www.w3schools.com" onMouseOver="document.bgcolor='lightgreen'">Visit W3Schools</a>
I tried applying this to radio buttons too that would change the bg color onclick, however If I wanted a preview of the color (by using onMouseOver) that part didn’t work as it doesn’t with the above.
Is the solution so obvious I’m overlooking it? Thanks for any help.
No, it’s not obvious. JavaScript is not so easy to handle. And you have to learn the types and names of the objects you can use in JavaScript.
The object
documentdoes not have a elementbgcolorWhat you are trying is to change the CSS-style of the element body of the document
One could do it by using the document object model (DOM) which is what you tried, but you have to respect the case. the correct form of the document’s attribute is
bgColornot bgcolor (Capital letter C).But it is not advisable. Why?
mostly responsible for the data and the structure of the … well
… document. The
bgColorattribute ofdocumentmaybe a relic ofthe dark HTML medieval, the pre CSS times.