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

27-02-2017 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:

How to submit form using javascript or jquery.
16-04-2017 javascript jquery submit form
How to use request module in node js
16-03-2017 request module node js
Filter for replace text in Angular Js
05-03-2017 filter replace angular js
How to get drop down value when drop down change using javascript
27-02-2017 onchange events dropdown javascript functions
Sample Validations in javascript
22-02-2017 validations javascript