0

Possible Duplicate:
I have a div with contentEditable=“true” and need to color the numbers entered

Here is my code that works well for coloring the numbers in editable div but the cursor is going to the start of the div and it should work normal when I press keyboard arrow buttons to traverse the string, also when i click "home" and "end" buttons, cursor should go as expected...

jQuery(document).ready(function(){

   $("#richTextField").keyup(function() {

      var divContent = $(this).text();
      var pattern = /(\d)/g;
      var replaceWith = '<span class="numberClass"'+ '>$1</span>';
      var highlighted = divContent.replace(pattern,replaceWith);

      $(this).html(highlighted);

   });

});
Community
  • 1
  • 1
RamSafari
  • 61
  • 1
  • 5

0 Answers0