Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.52 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to detect content change event on a div
  2. <?php $row="testing content" ?>
  3. <!-- my editor section-->
  4. <div id="editor">
  5.     <div id="options">
  6.         <span><a id="iimg">Insert Image from gallery</a></span>
  7.         <span>Upload image to gallery</span>
  8.         <span><a id="iheading">Heading</a></span>
  9.     </div>
  10.     <div id="product_descriptioncontent" contenteditable="true"><?php echo $row; ?>
  11.     </div><!-- viewable editor -->
  12.     <input type="hidden" name="textareacontent" value="" id="textareacontent" >
  13.     <!-- hidden field to submit values -->
  14. </div>
  15. <!-- end of editor section -->
  16. <div id="imc"></div> <!-- image gallery loading section -->
  17.  
  18. <script>
  19. $(document).ready(function(){
  20.  
  21.     $('#iheading').click(function(){
  22.     $('#product_descriptioncontent').append('<h1>Heading</h1>');
  23.     });
  24.  
  25.     $('#iimg').click(function(){
  26.         $('#imc').load('imagegallery.php',function(){
  27.         $('#gallery img').on('click',function(){
  28.             $('#product_descriptioncontent').append('<img  src="http://localhost/sites/site_pics/otherpic/1.png"><br>&nbsp;');
  29.     });
  30.     });
  31.     });
  32.     $('#product_descriptioncontent').change(function(){
  33.     alert("pppp");// how to capture this event
  34.     });
  35. });
  36. </script>
  37.        
  38. document.getElementById( 't' ).onkeypress = function( e ) {
  39.     var evt = e || window.event
  40.     alert( String.fromCharCode( evt.which ) )
  41. }​
  42.        
  43. $( '#product_descriptioncontent' ).on( 'keypress', function() {
  44.     $( '#your-hidden-input' ).val( $( this ).text() )
  45.     // Or
  46.     $( '#your-hidden-div' ).text( $( this ).text() )
  47. } )