[SalesForce] How to create “button” tag dynamically using $A.createComponent

I am able to dynamically create "ui:button" using $A.createComponent as shown in:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_dynamic_cmp_async.htm

However, I am not able to do the same for "button". Can somebody help me why is this happening and also how to render "button".

Best Answer

you need to use aura:html to create a html tag dynamically using $A.createComponent.

So to create a button tag below is how you do it:

$A.createComponent(
    "aura:html",
    {
        "tag":"button",
        "body":"click me",
        "HTMLAttributes":{
            "id":"dynamicbtn",
            "class":"slds-button slds-button--brand"
        }
    },
    function(newBtn){
        if (cmp.isValid()) {
            var body = cmp.get("v.body");
            body.push(newBtn);
            cmp.set("v.body", cmp);
        }
    }
);