Posted By

DesTincT on 07/25/08


Tagged

jquery caret text-cursor


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jamesming
wizard04


Set text cursor to the begin/end of input/textarea


 / Published in: JavaScript
 

Can use without jquery

  1. /* to the END */
  2.  
  3. $('textarea').each(function(){ //change event or something you want
  4.  
  5. /* simple js */
  6. if (this.createTextRange) {
  7. var r = this.createTextRange();
  8. r.collapse(false);
  9. r.select();
  10. }
  11.  
  12. $(this).focus(); //set focus
  13.  
  14. });
  15.  
  16. /* to the BEGIN */
  17.  
  18. $('textarea').each(function(){ //change event or something you want
  19.  
  20. /* simple js */
  21. if (this.createTextRange) {
  22. var r = this.createTextRange();
  23. r.collapse(true);
  24. r.select();
  25. }
  26.  
  27. $(this).focus(); //set focus
  28.  
  29. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: stavelin on September 16, 2008

do you have an example of this somewhere?

Posted By: necoxelans on February 27, 2009

easiest way is that: after page load use this script to focus on textbox:

document.formname.textboxname.focus();

than if you if you changed text value and want to go to end of this textbox, write that: document.formname.textboxname.value=document.formname.textboxname.value;

thats all folks :)

You need to login to post a comment.