Simple JavaScript Code to Change HTML Element Color

This simple JavaScript code example contains two simple functions to change text and background colors of a HTML element. Can be used separately or together. Very helpful JavaScript code for JavaScript beginners.


Sampled by © JavaScriptBank.com
Example 1
Change the background color using a fixed color in the script

Change Background color
Watch the background color change!


Example 2
Change text and background color with user-selected colors:

Text color:

Background color:

Change text and background color
Watch the text and background colors change!

2000+ free JavaScripts
at www.JavaScriptBank.com