Skip to content
Advertisement

Onclick attribute for button create inside Javascript not working

I’m stuck in a problem. The onclick property for the button created inside Javascript is not working Here is my code:
Click here
Reply function: Click here

Advertisement

Answer

try this

var button = document.createElement('button');
button.className = 'btn btn-outlline-primary';
button.value = 'Reply';
button.setAttribute("onclick", "YOURFUNCTIONNAME()");
div.appendChild(button);

you can give your button an onclick funtion with setAttribute

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement