JavaScript document.getElementById Edit Background Color

JavaScript document.getElementById Edit Background Color

We can use JavaScript like CSS to style a div element on a page to edit the background color. Lets say that you have a div id on a page called “topright” and you wanted to change the color to red with JavaScript.

[code]<div id="topright"></div>[/code]

Use the code below to change the color to red with JavaScript.

[code]<script>
document.getElementById("topright").style.backgroundColor = "red";
</script>[/code]

Change the color of a div to blue with JavaScript

[code lang=”js”]<script>
document.getElementById("topright").style.backgroundColor = "blue";
</script>[/code]

Only cool people share!

Change the color of a div to green with JavaScript

[code lang=”js”]<script>
document.getElementById("topright").style.backgroundColor = "green";</script>[/code]

JavaScript document.getElementById Edit Background Color

One of the best ways to learn is by tearing apart the code piece by piece to see what each character is doing. Take advantage of this code and remove parts to see what it does and then paste it back in.  That is the best way to learn JavaScript document.getElementById Edit Background Color

JavaScript document.getElementById Edit Background Color was last modified: May 8th, 2015 by Maximus Mccullough
Summary
JavaScript document.getElementById Edit Background Color
Article Name
JavaScript document.getElementById Edit Background Color
Description
We can use JavaScript like CSS to style a div element on a page to edit the background color.
Author
JavaScript document.getElementById Edit Background Color

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.