I am attaching onclick event on dynamically created button but the event is not firing.
var ind = location.href.indexOf('http://www.abc.com/');
function init(){
alert('h');
}
if(ind != -1){
var elem = document.createElement("input");
elem.id ='btnGumb';
elem.value = 'Select Check box';
elem.type = 'button';
elem.style.position = 'fixed';
elem.style.left = '0px';
elem.style.top = '0px';
//this is not working
elem.setAttribute('onclick', 'init();');
//but alert is working: elem.setAttribute('onclick', 'alert("h");');
document.body.appendChild(elem);
}