Skip to content

Instantly share code, notes, and snippets.

@milosdjakonovic
Last active November 26, 2015 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milosdjakonovic/2923209132c2d07c76ea to your computer and use it in GitHub Desktop.
Save milosdjakonovic/2923209132c2d07c76ea to your computer and use it in GitHub Desktop.
contenteditablechanged event for jQuery
/**
* jQuery contenteditablechanged
*
* Fires custom event named 'contenteditablechanged' when
* textcontent of element marked with contenteditable='true'
* changes.
*
* Usage:
* $('[contenteditable]').on('contenteditablechanged', function(e){
* console.log(e); //-- Event properits
* console.log(this); //-- Element
* } );
*
**/
$( document.body ).delegate( "[contenteditable='true']", "click", function() {
var $this = $(this);
$this.data('contenteditable-prevcontent', $this.text() ).one('blur', function(){
if( $this.data('contenteditable-prevcontent') !== $this.text() ){
$this.trigger('contenteditablechanged');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment