title: Unable to make selected text bold/underlined on clicking on tooltip
body: <p>I have some contenteditable paragraphs and I want to be able to make certain words bold underlined when double-clicked. When I double-click a word, it is selected and a tooltip with 3 options is displayed. However upon clicking the tooltip option, the selection is gone and no change has been made to the text.</p>
  
  <p>The questions are:
  1) How to bold the selected text?</p>
  
  <p>(Question 2 is not important or necessary.)
  2) How to keep the affected text selected?</p>
  
  <p>Solutions are highly preferred in javascript over jQuery.</p>
  
  <p>The following is the code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var allpara = document.querySelectorAll('p');
  [].forEach.call(allpara, function(para) {
    para.addEventListener('click', showTooltip, false);
  });
  
  var tooltip = document.getElementById('tooltip');
  
  function showTooltip(e) {
    tooltip.style.display = 'block';
  }
  
  var tooltipOptions = document.querySelectorAll('.tooltip-option');
  [].forEach.call(tooltipOptions, function(options) {
    options.addEventListener('click', function(e) {
      console.log(e.target.id);
      document.execCommand('bold');
    }, false);
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    position: relative;
  }
  #tooltip {
    display: none;
    position: fixed;
    background: black;
    color: white;
    width: 120px;
    font-size: 2em;
    border-radius: 4px;
    top: 10px;
    right: 150px;
  }
  .tooltip-option {
    width: 35px;
    margin-left: 10px;
    cursor: pointer;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;body&gt;
    &lt;div id="notepad"&gt;
      &lt;p class="notepad-paragraph" contenteditable="true"&gt;This is my text-ed&lt;/p&gt;
      &lt;p class="notepad-paragraph" contenteditable="true"&gt;itor. This is what I have&lt;/p&gt;
      &lt;p class="notepad-paragraph" contenteditable="true"&gt;built till no&lt;/p&gt;
      &lt;p class="notepad-paragraph" contenteditable="true"&gt;w. Now I am building it fur&lt;/p&gt;
      &lt;p class="notepad-paragraph" contenteditable="true"&gt;ther. This is fun.&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div id="tooltip"&gt;
      &lt;span id="tooltip-bold" class="tooltip-option"&gt;B&lt;/span&gt;
      &lt;span id="tooltip-und" class="tooltip-option"&gt;U&lt;/span&gt;
      &lt;span id="tooltip-red" class="tooltip-option"&gt;R&lt;/span&gt;
    &lt;/div&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>