samedi 27 juin 2015

function to create buttons receiving "text" and "onclick function" by parameter

I want to do what I said in the title. I tried this:

function createButton(func, text){
    var butt = document.createElement('BUTTON');
    var btTxt = document.createTextNode(text);
    btTxt.style.color = '#006633';
    btTxt.style.fontWeight = 'bold';
    butt.onclick = func;
    butt.appendChild(btTxt);
    butt.style.margin = '5px';
    document.body.appendChild(butt);
}

And this:

createButton(doSomething, click to do something);

But it doesn't work :/

Anyone?

Aucun commentaire:

Enregistrer un commentaire