Loop through the children of the current node in TinyMCE

Suppose I have a specific table selected in TinyMCE, for example:

var ed = tinyMCE.activeEditor; var selection = ed.selection.getContent(); var element = ed.dom.getParent(ed.selection.getNode(), 'table'); 

How do I scroll tr elements inside this?

I suspect that one of these methods may be appropriate, but I am so new to classes, it is difficult for me to understand how to apply them:

TinyMCE select (): http://www.tinymce.com/wiki.php/API3:method.tinymce.dom.DOMUtils.select

TinyMCE getAll (): http://www.tinymce.com/wiki.php/API3:method.tinymce.html.Node.getAll

+6
source share
2 answers

You can scroll through any node in tinymce like a regular html node, because they are actually regular html nodes.

So this will be enough:

 var ed = tinyMCE.activeEditor; var element = ed.dom.getParent(ed.selection.getNode(), 'table'); var child = element.firstChild; while(child){ if(child.nodeName.toLowerCase() == 'tr'){ //do your stuff here } child = child.nextSibling; } 
+7
source

Does var element have a childNodes property? This is an array of immediate children. Each of them will have properties in which nodeName will interest nodeName . Make a recursive function to search (each node has another childNodes ) until you find that nodeName=="TR" .

By the way, that would be a lot easier with jQuery if you're interested.

http://www.w3schools.com/htmldom/dom_methods.asp

http://www.w3schools.com/htmldom/dom_nodes_info.asp

+1
source

Source: https://habr.com/ru/post/907452/


All Articles