Issue #1922💬 AnsweredOpened March 26, 2019by sakshigarg90 reactions

InnerText/textContent not working on model

快速解答by sakshigarg9

Used a setTimeout function, worked with mdel.getEl().innerText realised there's a delay

Read full answer below ↓

Question

I'm using model.view.el.innerText to capture the innerText of the component in use when I update/change the text using an event, but it returns an empty string (ideally it should return the updated text), although if i use model.view.el.tagName or model.view.el.id it gives the desirable output(h2 and trial respectively). I also tried using model.view.el.textContent but still returns an empty string.

If I undo the update in text, model.view.el.innerText gives me the original text (Account Sign In). Thus, I believe the RTE changes/updates the text differently which does not process seamlessly into the element which is why model.view.el.innerText is returning an empty string.

my component looks like this:

<h2 id="trial" data-gjs-removable="false" data-gjs-draggable="false" data-gjs-droppable="false" data-gjs-stylable="false" data-gjs-highlightable="false" data-gjs-copyable="false" data-gjs-resizable="false" data-gjs-badgable="false" fa-arrow-up="false" data-gjs-toolbar="false">Account Sign In</h2>

my event looks like this:


   //track change in text
    editor.on('component:update:content', model => {
    console.log('New content', model.view.el.textContent);
    
  })

Answers (2)

sakshigarg9March 27, 2019

Used a setTimeout function, worked with mdel.getEl().innerText realised there's a delay

lock[bot]March 27, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.