Change div background color using javascript, you need to set a on click function in your div and set a id name. Now call the function name in the script and generate the dive background color to call div id name, for example:
document.getElementById(“div_id”).style.backgroundColor=”color code”;
Try it in your page:
<div on click="change_color()" id="change_div_coloe"> Change background color </div> <script type="text/javascript"> function change_color(){ document.getElementById("change_div_coloe").style.backgroundColor="rgb(250, 255, 189)"; } </script>
Question and answer is powered by AnsPress.io