Reputation: 30578
My Div have the contenteditable as true, but I would like to monitor the div, if there is updated. How can I monitor it using jquery? Thanks.
Upvotes: 2
Views: 79
Reputation: 195992
You can use the .blur()
or the .keypress()
event handling methods..
Demo at http://jsfiddle.net/gaby/nwCsr/
Update
to handle paste you can listen for the paste
event..
$('selector').bind('paste', function(){
// handle paste ..
});
Demo at http://jsfiddle.net/gaby/nwCsr/1/
Upvotes: 1
Reputation: 3323
you should use setInterval()
and check every second or so if the div is changed. If you're using AJAX, you could trigger the change event when the AJAX is complete. Also, I think you can use the onKeyPressed
or onKeyUp
event for that div.
Upvotes: 0
Reputation: 236022
You could have a look into mutation events for that purpose. In your case
$('#myDIV').bind('DOMSubtreeModified', function(e) {
});
That should fire every time, anything changes within that DOM subtree. I'm not sure if it works with a contentEditable however.
Example: http://jsfiddle.net/J6ARW/
One word of caution: Mutation events were declared 'deprecated' so it might be a nice tool to play around with, but maybe not wise to use for any production code.
Upvotes: 1