最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Removing a text from tinymce editor using javascript - Stack Overflow

matteradmin2PV0评论

I have a text <info>SOME CONTENTS GOES HERE</info>

How i can remove this text from the editor when I click on a button (custom button) using javascript function. I used this code:

dom.remove(dom.getParent(selection.getNode(), 'info')); 

But it is showing an error. Is there any solution?

Thanks in advance.

I have a text <info>SOME CONTENTS GOES HERE</info>

How i can remove this text from the editor when I click on a button (custom button) using javascript function. I used this code:

dom.remove(dom.getParent(selection.getNode(), 'info')); 

But it is showing an error. Is there any solution?

Thanks in advance.

Share edited Oct 22, 2010 at 15:14 Tarik 81.9k86 gold badges242 silver badges351 bronze badges asked Oct 21, 2010 at 14:33 Shinu ThomasShinu Thomas 5,31612 gold badges62 silver badges88 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

tinyMCE offers a method under DOMUtils which is tinymce.dom.DOMUtils/remove

// Removes all paragraphs in the active editor
tinyMCE.activeEditor.dom.remove(tinyMCE.activeEditor.dom.select('p'));

// Removes a element by id in the document
tinyMCE.DOM.remove('mydiv');

So in your case since you want to remove <info> and what's inside then you should write something like :

// Removes all paragraphs in the active editor
    tinyMCE.activeEditor.dom.remove(tinyMCE.activeEditor.dom.select('info'));
var a = ed.selection.getNode();
var txt = ed.selection.getContent();
var newT = document.createTextNode(txt);
a.parentNode.replaceChild(newT, a);
Post a comment

comment list (0)

  1. No comments so far