createElement

Create HTML elements using JavaScript 1.2kb (minified)

Live Demo


Output:

Basic Demo:


var basicDemo = createElement("div", "[class:newDiv]", "I'm a new <div>");
document.querySelector(".basic-demo").appendChild( basicDemo );

Advanced Demo:


var advancedDemo = createElement("a","[href:http://www.csslab.cl][style:background:#f00;]","CSSLab");
document.querySelector(".advanced-demo").appendChild( advancedDemo );

Nesting:


var firstItem = createElement("li","","List item 1"),
    secondItem = createElement("li","","List item 2"),
    thirdItem = createElement("li","","List item 3"),
    unorderedList = createElement("ul","[id:links]",[firstItem,secondItem,thirdItem]);
    document.querySelector(".nesting-demo").appendChild( unorderedList );