Skip to content

Instantly share code, notes, and snippets.

@natanverdes
Created December 1, 2015 16:22
Show Gist options
  • Save natanverdes/c97f912d2d2d80eae9e1 to your computer and use it in GitHub Desktop.
Save natanverdes/c97f912d2d2d80eae9e1 to your computer and use it in GitHub Desktop.
Añadir evento change a div con contenteditable
// Source: http://ask.webatall.com/javascript/9800_contenteditable-change-events.html
$('body').on('focus', '[contenteditable]', function() {
var $this = $(this);
$this.data('before', $this.html());
return $this;
}).on('blur keyup paste input', '[contenteditable]', function() {
var $this = $(this);
if ($this.data('before') !== $this.html()) {
$this.data('before', $this.html());
$this.trigger('change');
}
return $this;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment