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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -