setAtrtibute, f setAttributes, el.createElement
Creating element, setting attributes, body.appendChild();
by Miklos Nagy
HTML
<div id="dd"></div>
JavaScript
// Create a div and set class
var new_row = document.createElement("div");
new_row.setAttribute("class", "aClassName" );
// Add some text
new_row.appendChild( document.createTextNode("Some text") );
// Add it to the document body
document.body.appendChild( new_row );
var inp = document.createElement('input');
setAttributes(inp, {
"class" : "inpCl",
'placeholder' : "BaseValue"
});
document.body.appendChild( inp );
//Helpers
function setAttributes(el, attrs){
for(var key in attrs) {
el.setAttribute(key, attrs[key])
}
}