Report an issue
Class

CKEDITOR.dom.documentFragment

class

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

Methods

  • constructor( [ nodeOrDoc ] ) → documentFragment

    Creates a document fragment class instance.

    Parameters

    [ nodeOrDoc ] : document | DocumentFragment

    Defaults to CKEDITOR.document

    Returns

    documentFragment
  • append( node, [ toStart ] ) → node

    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 is true, however when force is set to true filler will be appended regardless of the environment.

    Parameters

    [ force ] : Boolean

    Append filler regardless of the environment.

  • appendTo( element ) → element

    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.

  • clone( [ includeChildren ], [ cloneId ] ) → node

    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.

  • since 4.12.0

    find( selector ) → nodeList

    Wrapper for querySelectorAll. Returns a list of elements within this document that match the specified selector.

    Note: The returned list is not a live collection (like the result of native querySelectorAll).

    Parameters

    selector : String

    A valid CSS selector.

    Returns

    nodeList
  • since 4.12.0

    findOne( selector ) → element

    Wrapper for querySelector. Returns the first element within this document that matches the specified selector.

    Parameters

    selector : String

    A valid CSS selector.

    Returns

    element
  • getChild( indices ) → node

    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

    nodeList
  • 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.

  • getFirst( evaluator ) → node

    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.

  • since 4.5.0

    getHtml() → String

    Gets the HTML of this document fragment's children.

    Returns

    String

    The HTML of this document fragment's children.

  • getLast( evaluator ) → node

    See getFirst.

    Parameters

    evaluator : Function

    Filtering the result node.

    Returns

    node
  • getNext( [ evaluator ] ) → node

    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.

  • getParent( [ allowFragmentParent ] ) → element

    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()