johnmosly johnmosly - 1 year ago 89
jQuery Question

trigger an event when contenteditable is changed

When a divs value is changed, how Can I trigger an event?

<div class="changeable" contenteditable="true"> Click this div to edit it <div>

So when its content changes I want to create an alert and/or do other things:

$('.changeable').text().change(function() {
alert('Handler for .change() called.');

Answer Source

Just store the contents to a variable and check if it is different after blur() event. If it is different, store the new contents.

var contents = $('.changeable').html();
$('.changeable').blur(function() {
    if (contents!=$(this).html()){
        alert('Handler for .change() called.');
        contents = $(this).html();


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download