create element javascript with id

JavaScript
var btn = document.createElement('div'); 
btn.setAttribute("id", "div1");var element = document.createElement("div"); //Create div
document.body.appendChild(element); //Add to bottom of <body> tagvar btn = document.createElement("BUTTON");   // Create a <button> element
btn.innerHTML = "CLICK ME";                   // Insert text
document.body.appendChild(btn);               // Append <button> to <body>
Source

Also in JavaScript: