When a divs value is changed, how Can I trigger an event?
Click this div to edit it
-
Another solution which is slightly modified version of previous ones but it may be more comfortable to use for some of you.
Idea is to save origin value and compare it with current value in 'blur' event. I save origin value as attribute of editable div tag (instead of creating variable for origin value). Using attribute as container for origin value is more comfortable when one has a huge number of editable divs in table (as cells). So it is easy to get origin value since you don't need to create many variables.
See my complete example code:
editable div
originValue
detecting changes in blur
var cells = $("#table").find('td>div[contenteditable=true]');
cells.each(function () {
$(this).blur(function() {
if ($(this).text() != $(this).attr("origin")) {
console.log('changed');
}
});
});