I need to call a JavaScript after pressing a button with type button.
<button type='button'
class='btn btn-sm btn-primary pull-right m-t-n-xs'
style='width: 100%;' id='demo' onclick='demo();'>
<strong>Edit</strong>
</button>
I've tried the JavaScript below but it has errors
$('#demo').click(function() {
alert('hey');
});
For the JS above, it doesn't have an error but it doesn't alert..
document.getElementById("demo").onclick = function() { myFunction() };
function myFunction() {
alert('hey');
}
The error for the js above is : Uncaught TypeError: Cannot set property 'onclick' of null at HTMLDocument.
window.onload = function() {
document.getElementById("demo").onclick=function() {
alert("Hello WOrld");
}
}
The error for this last one is:
Uncaught TypeError: Cannot set property 'onclick' of null
at window.onload