When creating an element, I often use the following syntax:
var foo = document.createElement('div');
To set the ID of the div, I would typically do this:
foo.setAttribute('id', 'divName');
After some searching online, I came across code similar to the following:
var google = createElement("a",{"href":"http://google.com"},"google"),
youtube = createElement("a",{"href":"http://youtube.com"},"youtube"),
facebook = createElement("a",{"href":"http://facebook.com"},"facebook"),
links_container = createElement("div",{"id":"links"},[google,youtube,facebook]);
Which seems equivalent to:
var foo = document.createElement('div', {'id':'divName');
However, when I tried running the above code, the ID "divName" was not added and instead an empty div was created. I'm puzzled about what I might be doing incorrectly, and whether it's actually possible to both create and set the div name for an element using .createElement exclusively?