title: how to replace my selected text in jQuery?
body: <p>how to replace selected text in html textarea?</p>
  
  <p><code>mardagz</code> to <code>[b]mardagz[\b]</code></p>
  
  <p>here's my code but won't work..</p>
  
  <pre><code>function getSelectedText(){ 
  if(window.getSelection){ 
      return window.getSelection().toString(); 
  } 
  else if(document.getSelection){ 
      return document.getSelection(); 
  } 
  else if(document.selection){ 
  
      return document.selection.createRange().text; 
  }} 
  
  
  
  function bbrep(start, end){
   $("#pPost").val($("#pPost").val().replace(getSelectedText(), start + getSelectedText() + end))};
  </code></pre>
  
  <p>key</p>
  
  <pre><code>$("#bbbold").click(function(){
            bbrep("[b]", "[/b]");
            return false;      
   })
  </code></pre>
  
  <p>anyone has an idea for this? :)</p>