Tinymce-4: Extrae texto solo de un enlace
Frecuentes
Visto 226 veces
0
In the tinymce.activeEditor I have this line of innerHTML-code (part of an ul-list):
<li><a href="#">Important words</a></li>
I put caret somewhere in the sentence "Important words", click a button with this line of code as part of the onclick-event:
seltxt = editor.selection.select(editor.selection.getNode()).text;
This selects/highlight the text "Important words" as it should, but unfortunally also the surrounding <a href>…</a>
. I don't want that, only the clean text between those a-tags.
I've seen close to houndres of select-text ideas but none so fare that can filter out/schrink selection to text withouth those a-tags using some smart short Javascript code. I don't want jquery!
Can someone solve this for me?
1 Respuestas
1
tinyMCE.activeEditor.selection.getSel().focusNode.textContent
textContent will give you the text
respondido 28 nov., 13:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript html tinymce-4 or haz tu propia pregunta.
This works nice (gets the text content only) but does not however select it in the editor as my previous setup did (my setup selected too much :) I try tweek this a little. But, yes, it did basically what I wanted too. When I apply a background color span to it, it sets bg color span twice, both on the text (inside of a-tag as I wanted) and outside the a-tag too (as I not wanted). Weird, but tnx mate! - Retroceso
wc buddy, i think you are talking about background color or foreground color plugin..in that you can tweak back/forecolor plugin and check if current selection is anchor tag and if so you have to find textcontent as i did here and wrap only it with the span tag.. - Vishal Sharma
Tnx, yes, thats what I figuered out too. Its not a color plugin but a menu system user can change dynamically (custom plugin). Wrapping a span around the text solved a long list of probs anoying me, and all works as a breeze now. - Retroceso