Skip to content

Instantly share code, notes, and snippets.

@MiguelSavignano
Last active March 1, 2017 17:44
Show Gist options
  • Save MiguelSavignano/b9e3264ecaea213620edc99d3b08588c to your computer and use it in GitHub Desktop.
Save MiguelSavignano/b9e3264ecaea213620edc99d3b08588c to your computer and use it in GitHub Desktop.
This delete the onclick string in the html dombut it's works same, auto create event listener with the code Example
window.ClearDOM = {
clearOnClick: function(element){
var code_block = $(element).attr('onclick')
$(element).on('click', function(event){
eval( code_block )
})
$(element).attr('onclick', '')
},
run: function(selector){
$('*[onclick]').toArray().forEach( (element) => ClearDOM.clearOnClick(element) )
}
}
ClearDOM.run()
@MiguelSavignano
Copy link
Author

MiguelSavignano commented Oct 6, 2016

Example:
<a onclick="console.log('its bad write here?')" >Example</a>
ClearDom.run()
Result
Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment