Alpha Delta
Alpha Delta

Reputation: 109

Why is the desired attribute not being added to the variable?

I don't get why the attributes are not being set to the variable Why is the colour not changing?

Here is the code :

var text = document.createElement('h2');
text.textContent = 'TEXT';
text.setAttribute("style", "color: red, margin-top:5px");
document.body.appendChild(text);

Upvotes: 2

Views: 40

Answers (1)

Lundstromski
Lundstromski

Reputation: 1247

Change color: red, margin-top:5px to color: red; margin-top:5px

var text = document.createElement('h2');
text.textContent = 'TEXT';
text.setAttribute("style", "color: red; margin-top:5px");
document.body.appendChild(text);

Upvotes: 2

Related Questions