Prev Demo
JavaScript
>
Setting CSS Style To HTML Element
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Setting CSS style to HTML element</h1> <script> function TestFunction() { document.getElementById("lblText").style.background = "red"; } </script> <label id="lblText">Click the button to change the background of this text.</label> <input type="button" id="btnTest" onclick="TestFunction()" value="Click me" /> <p><strong>Note:</strong> Click on the button to change the background color of the '0'</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output