onclick not running when specified in javascript -
when click button, doesn't run onclick. tried in console , worked fine. can help?
function customalert(message) { sect = document.createelement("section"); sect.classname = "alert"; sect.innerhtml = message + "<br /><br />"; var = document.createelement("button"); but.innerhtml = "gotcha."; but.onclick = "document.body.removechild(sect);"; sect.appendchild(but); document.body.appendchild(sect); }
you should use syntax:
but.onclick = function () { document.body.removechild(sect); }
so, onclick property
. means has value. when btn
clicked, javascript (the browser) calls property, expects function, code executed. instead, "sees" string , not know it.
Comments
Post a Comment