title: select dive text without last space
body: <p>I need to select the div content (the TEXT only without last space) on mouse click</p>
  
  <pre><code>&lt;div&gt;
                      &lt;div id="block1"&gt;
                          Please send the following code
                      &lt;/div&gt;
                      &lt;div id="block2" style="font-size:40px; background-color:#fffb95;" onclick="selectText('block2')" &gt;
                          @Html.DisplayFor(c =&gt; c.GeneratedCode, new { id = "genCode" })
                      &lt;/div&gt;
                      &lt;div id="block3"&gt;
                          to your vendor to generate an access code which is required for your authentication.
                      &lt;/div&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>the script </p>
  
  <pre><code>function selectText(containerid) {
          if (document.selection) { // IE
              var range = document.body.createTextRange();
              range.moveToElementText(document.getElementById(containerid));
              range.select();
          } else if (window.getSelection) {
              var range = document.createRange();
              range.selectNode(document.getElementById(containerid));
  
              window.getSelection().removeAllRanges();
              window.getSelection().addRange(range );
          }
      }
  </code></pre>
  
  <p>the style </p>
  
  <pre><code>#block1, #block2, #block3 {
          display: inline;
      }
  
      .input-lg {
          height: 43px;
      }
  </code></pre>
  
  <p>this is the output before selection 
  <a href="https://i.stack.imgur.com/2RZRr.png" rel="nofollow noreferrer">here</a>
  and when i select 
  <a href="https://i.stack.imgur.com/k3brM.png" rel="nofollow noreferrer">here</a>
  i want to remove last space from selection</p>