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:

How to search text in string using php ?

29-10-2017 php search string search

How to upload file by using request module

18-03-2017 request module node js

Convert Time 24 hrs to 12 hrs format In javascript

12-03-2017 date javascript 12hrs convert

Filter for insert HTML in Angular Js

06-03-2017 filter show html angular js html

Call a function every second or 5 seconds in javascript

22-02-2017 setinterval function calling