Created
December 1, 2015 16:22
-
-
Save natanverdes/c97f912d2d2d80eae9e1 to your computer and use it in GitHub Desktop.
Añadir evento change a div con contenteditable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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