title: Is there a replacement for document.execCommand? (or is it safe to use document.execCommand?)
body: <p>I am building an amateur rich text editor with vanilla JavaScript and document.execCommand() is essential to enabling the core features of an text editor. </p>
  
  <p>For example bold, italic and unordered list commands:</p>
  
  <pre><code>Array.from(toolbarBtn).forEach(btn =&gt; {
    btn.addEventListener('click', (e) =&gt; {
      e.preventDefault();
      if (e.target.id === "toolbar__btn--bold") {
        format('bold');
      }
      if (e.target.id === "toolbar__btn--italic") {
        format('italic');
      }
      if (e.target.id === "toolbar__btn--unorderedlist") {
        format('insertunorderedlist');
      }
  });
  });
  
  </code></pre>
  
  <p>However, when looking up this command on MDN Web Docs, I saw that this command is considered to be obsolete:</p>
  
  <blockquote>
    <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand" rel="noreferrer">Obsolete</a>
    This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.</p>
  </blockquote>
  
  <p>So, I'm wondering are there any replacement method in vanilla JavaScript, that could create all the Rich Text Editor features like execCommand() does?</p>
  
  <p>The Google search gave me no results, so at the same time, I wonder, how is that possible that the method is announced to be obsolete, but no alternative is suggested.</p>