title: Change CSS of selected text using Javascript
body: <p>I'm trying to make a JavaScript bookmarklet that will act as a highlighter, changing the background of selected text on a webpage to yellow when the bookmarklet is pressed.</p>
  <p>I'm using the following code to get the selected text, and it works fine, returning the correct string</p>
  <pre><code>function getSelText() {
      var SelText = '';
      if (window.getSelection) {
          SelText = window.getSelection();
      } else if (document.getSelection) {
          SelText = document.getSelection();
      } else if (document.selection) {
          SelText = document.selection.createRange().text;
      }
      return SelText;
  }
  </code></pre>
  <p>However, when I created a similar function to change the CSS of the selected text using jQuery, it isn't working:</p>
  <pre><code>function highlightSelText() {
      var SelText;
      if (window.getSelection) {
          SelText = window.getSelection();
      } else if (document.getSelection) {
          SelText = document.getSelection();
      } else if (document.selection) {
          SelText = document.selection.createRange().text;
      }
      $(SelText).css({'background-color' : 'yellow', 'font-weight' : 'bolder'});
  }
  </code></pre>
  <p>Any ideas?</p>