I\'m trying to modify this code to also give this div item an ID, however I have not found anything on google, and idName does not work. I read something about append
var g = document.createElement('div');
g.id = 'someId';
var element = document.createElement('tagname');
element.className= "classname";
element.id= "id";
try this you want.
Why not do this with jQuery?
var newDiv= $('<div/>', { id: 'foo', class: 'tclose'})
I'm not sure if you are trying to set an ID so you can style it in CSS but if that's the case what you can also try:
var g = document.createElement('div');
g.className= "g";
and that will name your div so you can target it.
You should use the .setAttribute() method:
g = document.createElement('div');
g.setAttribute("id", "Div1");
You can use g.id = 'desiredId'
from your example to set the id of the element you've created.