Forum menu
Quick basic JavaScr...
 

[Closed] Quick basic JavaScript help please

 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 9:28 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

divTag.className = “pixel”;

that took years off my life.


 
Posted : 18/10/2020 9:42 pm
Posts: 2087
Free Member
 

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


 
Posted : 18/10/2020 9: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 10:28 pm