Javascript examples for CSS Style Property:backgroundColor
Set a background color of a specific <div> element:
<!DOCTYPE html> <html> <head> <style> #myDIV {// w w w .ja v a 2s . com width: 300px; height: 300px; background-color: coral; color: white; } </style> </head> <body> <button onclick="myFunction()">Test</button> <div id="myDIV"> <h1>Hello</h1> </div> <script> function myFunction() { document.getElementById("myDIV").style.backgroundColor = "red"; } </script> </body> </html>