I create a div with id, class and a button in it
After created, i want to manipulate it, so i use getElementById
It work in the function where it be created but cannot use it on other function.
Error : "Uncaught TypeError: Cannot set property 'onclick' of null"
function ManageButton() {
var divManage = document.createElement('div');
divManage.classList.add('ol-opt');
divManage.classList.add('ol-unselectable');
divManage.classList.add('ol-control');
divManage.classList.add('ol-opt-expand');
divManage.setAttribute("id", "dbm");
document.querySelector("#map").appendChild(divManage);
var but = document.createElement('button');
but.classList.add('opt-button');
but.type = "button";
but.title = "Manage options";
var text = document.createTextNode('⌥');
but.appendChild(text);
document.getElementById('dbm').appendChild(but);
};
document.body.onload = ManageButton;
Error line :
document.getElementById('dbm').onclick = ManageEvent;
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment