javascriptdojoelementdocumentcreateelement

document createElement shortest syntax


I'm looking for the shortest syntax which could provide me the same result as this dojo line:

var divblock5 = dojo.create("div", {className: "barlittle", id: "block5"});

but I want to use plain JavaScript instead of dojo framework. I have a lot of dynamic element creation and I want to make my code short as possible.


Solution

  • createElement = function(type, className, id) {
        var element = document.createElement(type);
        element.className = className;
        element.id = id;
    
        return element;
    }