title: What do selectionStart and selectionEnd signify for textarea?
body: <p>I came across following code snippet to insert enter into the the text in a textarea where ctrl + enter is pressed.</p>
  
  <pre><code>$("#txtChatMessage").keydown(MessageTextOnKeyEnter);
  function MessageTextOnKeyEnter(e) {
      console.log(this.selectionEnd);
      if (e.keyCode == 13) {
          if (e.ctrlKey) {
              var val = this.value;
              if (typeof this.selectionStart == "number" &amp;&amp; typeof this.selectionEnd == "number") {
                  var start = this.selectionStart;
  
                  this.value = val.slice(0, start) + "\n" + val.slice(this.selectionEnd);
                  this.selectionStart = this.selectionEnd = start + 1;
              } else if (document.selection &amp;&amp; document.selection.createRange) {
                  this.focus();
                  var range = document.selection.createRange();
                  range.text = "\r\n";
                  range.collapse(false);
                  range.select();
              }
          }
          return false;
      }
  }
  </code></pre>
  
  <p>What I don't understand is what do selectionStart and selectionEnd mean here ? According to documentation that I read, selectionStart-End contain the start-end of selected text in the input element. However, here no text is explicitly selected. On doing console.log I could see that both these properties always have some value even when the text is not selected. Why is that?</p>