title: Get content from contenteditable div
body: <p>I display a popup for the user where it is required to write some text, and I want to check if he wrote something to display the message accordingly.</p>
  <p>HTML</p>
  <pre><code>&lt;div id=&quot;pop-div-id&quot; class=&quot;cont-pop-div&quot;&gt;
    &lt;p id=&quot;content-id&quot; contenteditable=&quot;true&quot; class=&quot;cont-pop&quot; placeholder=&quot;type explanation&quot; spellcheck=&quot;false&quot;&gt;&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Here is my JavaScript. I commented the use of <code>textContent</code> because I kept getting <code>content</code> has <code>undefined</code> value. The issue here is that this always alerts <code>You have to write something</code> and I am not sure what I am doing wrong that the value is not being updated even if I write something there.</p>
  <pre><code>let content =  document.getElementById(&quot;content-id&quot;);
  // let contentValue = content.textContent;
  // console.log(contentValue);
  
  let innerText = content.innerText;
  
     if (innerText[innerText.length-1] === '\n') { 
        innerText = innerText.slice(0,-1);
        console.log(innerText);
     }            
  
  button.addEventListener(&quot;click&quot;, function () {
    if (innerText.length === 0 || !!innerText.trim()) {
       alert(&quot;You have to write something &quot;);
    } else {
       alert(&quot;Hello&quot;);
    }
  });
  </code></pre>
  <p>I have seen this similar post - <a href="https://stackoverflow.com/questions/3593626/get-the-text-content-from-a-contenteditable-div-through-javascript">get the text content from a contenteditable div through javascript</a>
  but apparently I am doing something wrong</p>