Sandeep Roy Sandeep Roy - 1 year ago 141
HTML Question

JavaScript not changing HTML Styles

I am trying to change the color of my name, by clicking on a button. Here is what I've done till now,

<p id="demo">Sandeep Roy</p>
<button type="button" onclick="change()">Click</button>
function change() {
var x=document.getElementById("demo");;

The expected output is a red font, when 'click' button is clicked.

Unfortunately nothing happens when I do that, i.e same black color font.
Please help me educating in this matter.

Answer Source

In the below, you're missing quotas

var x=document.getElementById("demo");;

should be

var x=document.getElementById("demo");'red';

besides that - this approach is awful. Toggling classes is more preffered.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download