Prevent inline onclick from external javascript file -
is there way prevent inline onclick attributes external js file?
<button id="mybutton" type="button" onclick="alert('dont show me please!');" >click me</button>
in script.js:
var mybutton = document.getelementbyid("mybutton").addeventlistener("click", preventit); function preventit(e){ console.log('click event...'); e.preventdefault(); }
assume can't change html markup.
you remove onclick attribute so:
document.getelementsbyid("mybutton").removeattribute("onclick");
Comments
Post a Comment