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


/ Published in: JavaScript
Save to your folder(s)

Can use without jquery


Copy this code and paste it in your HTML
  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

You need to login to post a comment.