title: How can i deal with bidirectional text & numbers in pure JavaScript substring method?
body: <p>I am trying to get part of the text from an input element, depending on where the user clicked, but if I click in between the 1 and 0, the result is wrong &quot;שלום 1&quot;, it should be &quot;שלום 0&quot;.
  I tried adding CSS &quot;unicode-bidi: plaintext;&quot; to the input element.
  It did not help fix the problem.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myInput = document.getElementById("myInput")
  myInput.value = "שלום 10 hello";
  
  alert("Needs to be: 'שלום 0' \n Result '"+myInput.value.substring( 0, 6 )+"'")
  
  function mouseUp(){
   alert("Result '"+myInput.value.substring( 0, myInput.selectionStart )+"'")
  }
  myInput.addEventListener("mouseup", mouseUp);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id="myInput" style="direction: rtl;unicode-bidi: plaintext;"&gt;</code></pre>
  </div>
  </div>
  </p>