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:

Convert and download html to pdf without saving file

28-10-2018 node js convert html to pdf pdf download pdf without saving

File Upload Using Angular Js and Node Js

28-05-2018 AngularJs Node js file upload multer module

How to search text in string using php ?

29-10-2017 php search string search

Use java script file client side and server side at a time in node js

30-07-2017 node js include call javascript

How to submit form using javascript or jquery.

16-04-2017 javascript jquery submit form