Content editable change event in jQuery
In jQuery, there is no specific event for contenteditable change. However, we can use the input
event to detect changes in the contenteditable element.
Here's an example of how to use the input
event to detect changes in a contenteditable element:
HTML:
<div contenteditable="true" id="editable">Editable content</div>
jQuery:
$('#editable').on('input', function() {
console.log('Content changed!');
});
This will log "Content changed!" to the console every time the content of the #editable
element is changed.
Alternatively, we can use the keyup
event to detect changes in a contenteditable element. Here's an example:
HTML:
<div contenteditable="true" id="editable">Editable content</div>
jQuery:
$('#editable').on('keyup', function() {
console.log('Content changed!');
});
This will log "Content changed!" to the console every time a key is released while the #editable
element is in focus.
Note that both of these methods will detect any changes made to the contenteditable element, including changes made by pasting or cutting text.