Quick basic JavaScr...
 

MegaSack DRAW - 6pm Christmas Eve - LIVE on our YouTube Channel

[Closed] Quick basic JavaScript help please

3 Posts
2 Users
0 Reactions
73 Views
 Earl
Posts: 1902
Free Member
Topic starter
 

I know his is simple stuff but I'm stumped

I've managed to insert a div with a id of 'Id_1'. However it doesn't get my css class of 'pixel'. Why?

divTag = document.createElement("div");
divTag.class = "pixel";
divTag.id = "Id_1"
document.getElementById("aRow").appendChild(divTag);


 
Posted : 18/10/2020 8:28 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

divTag.className = “pixel”;

that took years off my life.


 
Posted : 18/10/2020 8:42 pm
Posts: 2086
Free Member
 

‘class’ is a reserved word, hence it needing to be ‘className’. Same for ‘for’, and is ‘htmlFor’ instead.


 
Posted : 18/10/2020 8:53 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

Makes sense. No wonder google was always came up with JS classes.
Much thanks.


 
Posted : 18/10/2020 9:28 pm