I want to run a function when a user edits the content of a div with contenteditable attribute. What\'s the equivalent of an onchange
div
contenteditable
onchange
Based on @balupton's answer:
$(document).on('focus', '[contenteditable]', e => { const self = $(e.target) self.data('before', self.html()) }) $(document).on('blur', '[contenteditable]', e => { const self = $(e.target) if (self.data('before') !== self.html()) { self.trigger('change') } })