how to createElement with an id in one line
15:27 07 Sep 2017

i know that i can create an element such as:

var foo = document.createElement('div');

and to set the div id i would do as such:

foo.setAttribute('id', 'divName');

and if you google long enough you will find someone doing code such as here

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_conteiner = createElement("div",{"id":"links"},[google,youtube,facebook]);

which would equal out to:

var foo = document.createElement('div', {'id':'divName);

yet when i run the above code the id or divName is not added and instead an empty div is created. so i am curious what i am doing wrong, and if it is even possible to both create and set the div name for an element using .createElement only?

javascript jquery html css