title: JavaScript - How to remove new line from textarea if no text exists before?
body: <p>I have a <code>textarea</code> and I want to remove new lines from it, if the return key is pressed, without writing any text. I tried this, but it did not work:</p>
  
  <pre><code>function keypress(id) {
    $("#"+id).keypress(function(event) {
      $("#"+id).val().replace(/\n/g, "");
    });
  }
  </code></pre>