How to detect content change event on a div

Try adding a handler for DOMCharacterDataModified. Might be a cleaner solution.


Do you like this? http://jsfiddle.net/Ralt/hyPQC/

document.getElementById( 't' ).onkeypress = function( e ) {
    var evt = e || window.event
    alert( String.fromCharCode( evt.which ) )
}​

It's not waiting for a change event, it's kind of pointless.

Instead, it's listening to the onkeypress event. Everytime a user changes the content of this div (by adding a character to it), it triggers the event.

You can also see how to get the character clicked (using String.fromCharCode( evt.which )).

PS: a full jQuery solution for your specific case would be this:

$( '#product_descriptioncontent' ).on( 'keypress', function() {
    $( '#your-hidden-input' ).val( $( this ).text() )
    // Or
    $( '#your-hidden-div' ).text( $( this ).text() )
} )