Return to Snippet

Revision: 47473
at June 8, 2011 18:35 by griffpup


Initial Code
  // solution found here http://jsfiddle.net/edelman/KcX6A/1/
  
  <div id="selectme" contenteditable='true'>Some text goes here!</div>
  <p>Click me!</p>

  function SelectText(element) {
      var text = document.getElementById(element);
      if ($.browser.msie) {
          var range = document.body.createTextRange();
          range.moveToElementText(text);
          range.select();
      } else if ($.browser.mozilla || $.browser.opera) {
          var selection = window.getSelection();
          var range = document.createRange();
          range.selectNodeContents(text);
          selection.removeAllRanges();
          selection.addRange(range);
      } else if ($.browser.safari) {
          var selection = window.getSelection();
          selection.setBaseAndExtent(text, 0, text, 1);
      }
  }

  $(function() {
      $('p').click(function() {
          SelectText('selectme');   
      });
  });

Initial URL

                                

Initial Description

                                

Initial Title
jquery select text

Initial Tags
textmate, jquery

Initial Language
Other