Posted By

griffpup on 06/08/11


Tagged

select textmate jquery


Versions (?)

jquery select text


 / Published in: Other
 

  1. <div id="selectme" contenteditable='true'>Some text goes here!</div>
  2. <p>Click me!</p>
  3.  
  4. function SelectText(element) {
  5. var text = document.getElementById(element);
  6. if ($.browser.msie) {
  7. var range = document.body.createTextRange();
  8. range.moveToElementText(text);
  9. range.select();
  10. } else if ($.browser.mozilla || $.browser.opera) {
  11. var selection = window.getSelection();
  12. var range = document.createRange();
  13. range.selectNodeContents(text);
  14. selection.removeAllRanges();
  15. selection.addRange(range);
  16. } else if ($.browser.safari) {
  17. var selection = window.getSelection();
  18. selection.setBaseAndExtent(text, 0, text, 1);
  19. }
  20. }
  21.  
  22. $(function() {
  23. $('p').click(function() {
  24. SelectText('selectme');
  25. });
  26. });

Report this snippet  

You need to login to post a comment.