1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)

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.

<div id="topright"></div>

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

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

Change the color of a div to blue with JavaScript

<script>
document.getElementById("topright").style.backgroundColor = "blue";
</script>

Change the color of a div to green with JavaScript

<script>
document.getElementById("topright").style.backgroundColor = "green";</script>

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

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
JavaScript document.getElementById Edit Background Color was last modified: May 8th, 2015 by Maximus Mccullough

Subscribe To My YouTube Channel:

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips

Tips

Cool People Share:
JavaScript document.getElementById Edit Background Color

Leave a Reply

Your email address will not be published. Required fields are marked *

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