CKEDITOR.dom.documentFragment
DocumentFragment is a "lightweight" or "minimal" Document object. It is commonly used to extract a portion of the document's tree or to create a new fragment of the document. Various operations may take document fragment objects as arguments and result in all the child nodes of the document fragment being moved to the child list of this node.
Filtering
Properties
-
type : Number
readonly
The node type. This is a constant value set to CKEDITOR.NODE_DOCUMENT_FRAGMENT.
Defaults to
CKEDITOR.NODE_DOCUMENT_FRAGMENT
Methods
-
constructor( [ nodeOrDoc ] ) → documentFragment
Creates a document fragment class instance.
-
Append a node as a child of this element.
var p = new CKEDITOR.dom.element( 'p' ); var strong = new CKEDITOR.dom.element( 'strong' ); p.append( strong ); var em = p.append( 'em' ); // Result: '<p><strong></strong><em></em></p>'
Parameters
node : node | String
The node or element name to be appended.
[ toStart ] : Boolean
Indicates that the element is to be appended at the start.
Defaults to
false
Returns
node
The appended node.
-
appendBogus( [ force ] )
Appends a
<br>
filler element to this element if the filler is not present already. By default filler is appended only if CKEDITOR.env.needsBrFiller istrue
, however whenforce
is set totrue
filler will be appended regardless of the environment.Parameters
[ force ] : Boolean
Append filler regardless of the environment.
-
Makes this node a child of another element.
var p = new CKEDITOR.dom.element( 'p' ); var strong = new CKEDITOR.dom.element( 'strong' ); strong.appendTo( p ); // Result: '<p><strong></strong></p>'.
Parameters
element : element
The target element to which this node will be appended.
Returns
element
The target element.
-
Clones this node.
Note: Values set by {#setCustomData} will not be available in the clone.
Parameters
[ includeChildren ] : Boolean
If
true
then all node's children will be cloned recursively.Defaults to
false
[ cloneId ] : Boolean
Whether ID attributes should be cloned, too.
Defaults to
false
Returns
node
Clone of this node.
-
Wrapper for
querySelectorAll
. Returns a list of elements within this document that match the specifiedselector
.Note: The returned list is not a live collection (like the result of native
querySelectorAll
).Parameters
selector : String
A valid CSS selector.
Returns
-
Wrapper for
querySelector
. Returns the first element within this document that matches the specifiedselector
. -
Gets a DOM tree descendant under the current node.
var strong = p.getChild( 0 );
Parameters
indices : Array | Number
The child index or array of child indices under the node.
Returns
node
The specified DOM child under the current node. Null if child does not exist.
-
getChildCount() → Number
Gets number of element's children.
Returns
Number
-
getChildren() → nodeList
Gets the nodes list containing all children of this element.
Returns
-
getDocument() → document
Gets the document containing this element.
var element = CKEDITOR.document.getById( 'example' ); alert( element.getDocument().equals( CKEDITOR.document ) ); // true
Returns
document
The document.
-
Gets the first child node of this element.
var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b></div>' ); var first = element.getFirst(); alert( first.getName() ); // 'b'
Parameters
evaluator : Function
Filtering the result node.
Returns
node
The first child node or null if not available.
-
getHtml() → String
since 4.5.0
Gets the HTML of this document fragment's children.
Returns
String
The HTML of this document fragment's children.
-
See getFirst.
-
Gets the node that follows this element in its parent's child list.
var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b><i>next</i></div>' ); var last = element.getFirst().getNext(); alert( last.getName() ); // 'i'
Parameters
[ evaluator ] : Function
Filtering the result node.
Returns
node
The next node or null if not available.
-
Gets the parent element for this node.
var node = editor.document.getBody().getFirst(); var parent = node.getParent(); alert( parent.getName() ); // 'body'
Parameters
[ allowFragmentParent ] : Boolean
Consider also parent node that is of fragment type CKEDITOR.NODE_DOCUMENT_FRAGMENT.
Defaults to
false
Returns
element
The parent element.
-
getPrevious( [ evaluator ] ) → node
Gets the node that preceeds this element in its parent's child list.
var element = CKEDITOR.dom.element.createFromHtml( '<div><i>prev</i><b>Example</b></div>' ); var first = element.getLast().getPrev(); alert( first.getName() ); // 'i'
Parameters
[ evaluator ] : Function
Filtering the result node.
Returns
node
The previous node or null if not available.
-
insertAfterNode( node )
Inserts the document fragment content after the specified node.
Parameters
node : node
-
insertBefore( node ) → node
Inserts this element before a node.
var em = new CKEDITOR.dom.element( 'em' ); var strong = new CKEDITOR.dom.element( 'strong' ); strong.insertBefore( em ); // result: '<strong></strong><em></em>'
Parameters
node : node
The node that will succeed this element.
Returns
node
The node being inserted.
-
ltrim()
-
moveChildren( target, [ toStart ] )
Moves this element's children to the target element.
Parameters
target : element
[ toStart ] : Boolean
Insert moved children at the beginning of the target element.
Defaults to
false
-
replace()
-
rtrim()
-
trim()