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?
You need to set styles of the button, not TextNode object:
function createButton(func, text) {
var butt = document.createElement('BUTTON');
var btTxt = document.createTextNode(text);
butt.style.color = '#006633';
butt.style.fontWeight = 'bold';
butt.onclick = func;
butt.appendChild(btTxt);
butt.style.margin = '5px';
document.body.appendChild(butt);
}
createButton(doSomething, 'click to do something');
function doSomething() { alert('Hello'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With