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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -