adding onclick event to dynamically added button?

前端 未结 8 1526
天命终不由人
天命终不由人 2020-12-03 01:50

I am adding a button dynamically in html like below: On click of that button I want to call a Javascript function:

var but = document.createElement(\"button\         


        
8条回答
  •  悲哀的现实
    2020-12-03 02:24

    try this:

    but.onclick = callJavascriptFunction;
    

    or create the button by wrapping it with another element and use innerHTML:

    var span = document.createElement('span');
    span.innerHTML = '

提交回复
热议问题