title: How to select the text from right to left in javascript
body: <p>I'm trying to create a selection that goes from right to left in the text,this is the code which i am using(it is acheived using mousemove)</p>
  
  <pre><code>    getWordAtPoint: function (elem, x, y) {
              if (elem.nodeType == elem.TEXT_NODE) {
     var sel = window.getSelection();
                  var range = elem.ownerDocument.createRange();
                  range.selectNodeContents(elem);
                  var currentPos = 0;
                  var endPos = range.endOffset;
                  while (currentPos &lt; endPos) {
                      range.setStart(elem, currentPos);
                      range.setEnd(elem, currentPos + 1);
                      if (range.getBoundingClientRect().left &lt;= x &amp;&amp; range.getBoundingClientRect().right &gt;= x &amp;&amp;
                         range.getBoundingClientRect().top &lt;= y &amp;&amp; range.getBoundingClientRect().bottom &gt;= y) {
                          var ret = range.toString();
                          range.setStart(sel.anchorNode, sel.anchorOffset);
                          sel.removeAllRanges();
                          sel.addRange(range);
                          range.detach();
                          return (range);
                      }
                      currentPos += 1;
                  }
              } else {
                  for (var i = 0; i &lt; elem.childNodes.length; i++) {
                      var range = elem.childNodes[i].ownerDocument.createRange();
                      range.selectNodeContents(elem.childNodes[i]);
                      if (range.getBoundingClientRect().left &lt;= x &amp;&amp; range.getBoundingClientRect().right &gt;= x &amp;&amp;
                         range.getBoundingClientRect().top &lt;= y &amp;&amp; range.getBoundingClientRect().bottom &gt;= y) {
                          range.detach();
                          return (this._getWordAtPoint(elem.childNodes[i], x, y));
                      } else {
                          range.detach();
                      }
                  }
              }
              return (null);
          },
  </code></pre>