How to change background color and color to the text using javascript

css
javascript
colors

Here we are using onchange() for changing the text colors and background colors. 


Sample Code

 
<script>
function color(){
	var color = document.getElementById('color').value;
	document.getElementById('text').style.color = color;
}
function textBgcolor(){
	var color = document.getElementById('bgcolor').value;
	document.getElementById('text').style.backgroundColor = color;
}
</script>
<select onchange="color()" id="color">
<option value="black">Select Black</option>
<option value="red">Select Red</option>
<option value="blue">Select Blue</option>
<option value="green">Select Green</option>
</select><br>
<select onchange="textBgcolor()" id="bgcolor">
<option value="black">Select Black</option>
<option value="red">Select Red</option>
<option value="blue">Select Blue</option>
<option value="green">Select Green</option>
</select>
<div id="text">Sample Code</div>

You might also like:

Time Sorting Ascending or Descending Order in Javascript

19-07-2017 Javascript ascending order descending order

Sanitization in java sript

14-03-2017 sanitization java script

Using slice remove last two characters from given string

07-03-2017 slice remove

Filter for change Date format (MM-dd-yyyy) in Angular Js

05-03-2017 mm-dd-yyyy date formats angular js

Send Mail in Node Js

21-02-2017 node js mail npm module