question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

selected content parent tag remove

See original GitHub issue

https://github.com/artf/grapesjs/issues/906#issuecomment-381403858

I need to remove the html content from editor.getSelected(). Now I’m using,

var selectedContent = editor.getSelected();
selectedContent.set('content', '');
selectedContent.components(MYHTML);

While I use selectedContent.set(‘content’, ‘’); it remove all the inner html. But didn’t remove the parent tag. For example, Before: <h2 id="it4a"><p>Sample Update Check Done</p></h2> After: <h2 id="it4a"></h2>

After set the components, its like <h2 id="it4a">NEW HTML</h2>. How to remove the parent tags while set the innerHtml empty?

Guide me how to solve this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
afdallahcommented, Jun 27, 2019

Have you seen this #1077 answer by @artf I think it’s suited with your case.

const component = editor.getSelected();
const coll = component.collection;
const at = coll.indexOf(component);
coll.remove(component);
return coll.add('<div>New content</div>', { at });
0reactions
prabha-912commented, Jul 3, 2019

I got the CSS too. By using this.htmlEditor..getContent(), this.cssEditor..getContent() I get all the content properly. 😃. Thanks for your response @afdallah.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove the parent element using plain Javascript
If you want to delete whatever is inside the <tr> tags, by clicking on the "Delete ...
Read more >
Remove the parent Element of a Node using JavaScript
To remove the parent element of a node, select the child node and use the `parentElement` property to get access to the parent...
Read more >
How to remove parent element except its child element using ...
Given an HTML document and the task is to remove the parent element except for its child element. Approach 1: Use contents() method...
Read more >
.remove() | jQuery API Documentation
A selector expression that filters the set of matched elements to be removed. Similar to .empty() , the .remove() method takes elements out...
Read more >
Element.remove() - Web APIs - MDN Web Docs
The Element.remove() method removes the element from the DOM.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found