Skip to content

Instantly share code, notes, and snippets.

@ridhotegar
Last active December 23, 2021 05:03
Show Gist options
  • Save ridhotegar/12eb206c778a8702bd9ca6f568301e14 to your computer and use it in GitHub Desktop.
Save ridhotegar/12eb206c778a8702bd9ca6f568301e14 to your computer and use it in GitHub Desktop.
Disable all onclick on page html with jquery
let clickAct = []
const _do = {
disable: () => {
let el = $('[onclick]'), count = el.length
el.each((i, e) => {
$(e).addClass(`click_${i}`)
clickAct[i] = $(e).attr('onclick')
if(!--count) { el.removeAttr("onclick") }
})
},
enable: () => {
clickAct.forEach((e, i) => {
$(`.click_${i}`).attr('onclick', clickAct[i])
$(`.click_${i}`).removeClass(`click_${i}`)
})
}
}
//-- how to
_do.disable()
/* yourcode */
_do.enable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment