I know we can insert the code to the top this way.
ed.selection.setCursorLocation(ed.getBody().firstChild, 0);
But, I am not sure how to implement this for content at the bottom.
Another approach:
function getTextNodes(node, nodeType, result){
var children = node.childNodes;
var nodeType = nodeType ? nodeType : 3;
var result = !result ? [] : result;
if (node.nodeType == nodeType) {
result.push(node);
}
for (var i=0; i<children.length; i++) {
result = this.getTextNodes(children[i], nodeType, result)
}
return result;
};
// get all Textnodes from lastchild, calc length
var textnodes = getTextNodes(ed.getBody().lastChild);
// set Cursor to last position
ed.selection.setCursorLocation(textnodes[textnodes.length-1], textnodes[textnodes.length-1].textContent.length );
You can use the following to DOMUtils.add() method to add a new HTML element to the document body.
For example, the following adds an empty paragraph with a CSS Class of "text_it"
ed.dom.add(ed.getBody(), 'p', {'class' : 'text_it'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With