Report an issue
Class

CKEDITOR.htmlParser.element

class

A lightweight representation of an HTML element.

Filtering

Properties

  • attributes : Object

    Stores the attributes defined for this element.

  • children : Array

    The nodes that are direct children of this element.

    Defaults to []

  • name : String

    The element name.

  • type : Number

    readonly

    The node type. This is a constant value set to CKEDITOR.NODE_ELEMENT.

    Defaults to CKEDITOR.NODE_ELEMENT

  • _ : Object

    private

Methods

  • constructor() → node

    inherited

    Creates a node class instance.

    Returns

    node
  • add( node, [ index ] )

    Adds a node to the element children list.

    Parameters

    node : node

    The node to be added.

    [ index ] : Number

    From where the insertion happens.

  • addClass( className )

    since 4.4.0

    Adds a class name to the list of classes.

    Parameters

    className : String

    The class name to be added.

  • clone() → element

    Clones this element.

    Returns

    element

    The element clone.

  • filter( filter ) → Boolean

    since 4.1.0

    Filters this element and its children with the given filter.

    Parameters

    filter : filter

    Returns

    Boolean

    The method returns false when this element has been removed or replaced with another. This information means that filterChildren has to repeat the filter on the current position in parent's children array.

  • filterChildren( filter )

    Filters this element's children with the given filter.

    Element's children may only be filtered once by one instance of the filter.

    Parameters

    filter : filter
  • find( criteria, [ recursive ] ) → node[]

    Searches through the current node children to find nodes matching the criteria.

    Parameters

    criteria : String | Function

    Tag name or evaluator function.

    [ recursive ] : Boolean

    Defaults to false

    Returns

    node[]
  • findOne( criteria, [ recursive ] ) → node | null

    Searches through the children of the current element to find the first child matching the criteria.

    element.findOne( function( child ) {
        return child.name === 'span' || child.name === 'strong';
    } ); // Will return the first child which is a <span> or a <strong> element.
    

    Parameters

    criteria : String | Function

    Tag name or evaluator function.

    [ recursive ] : Boolean

    If set to true, it will iterate over all descendants. Otherwise the method will only iterate over direct children.

    Defaults to false

    Returns

    node | null

    The first matched child, null otherwise.

  • forEach( callback, [ type ], [ skipRoot ] )

    since 4.1.0

    Executes a callback on each node (of the given type) in this element.

    // Create a <p> element with foo<b>bar</b>bom as its content.
    var elP = CKEDITOR.htmlParser.fragment.fromHtml( 'foo<b>bar</b>bom', 'p' );
    elP.forEach( function( node ) {
        console.log( node );
    } );
    // Will log:
    // 1. document fragment,
    // 2. <p> element,
    // 3. "foo" text node,
    // 4. <b> element,
    // 5. "bar" text node,
    // 6. "bom" text node.
    

    Parameters

    callback : Function

    Function to be executed on every node. Since 4.3: If callback returned false, the descendants of the current node will be ignored.

    Properties
    node : node

    Node passed as an argument.

    [ type ] : Number

    Whether the specified callback will be executed only on nodes of this type.

    [ skipRoot ] : Boolean

    Do not execute callback on this element.

  • getAscendant( condition ) → element

    since 4.3.0 inherited

    Gets the closest ancestor element of this element which satisfies given condition

    Parameters

    condition : String | Object | Function

    Name of an ancestor, hash of names or validator function.

    Returns

    element

    The closest ancestor which satisfies given condition or null.

  • getFirst( condition ) → node

    since 4.3.0

    Gets this element's first child. If condition is given, this method returns the first child which satisfies that condition.

    Parameters

    condition : String | Object | Function

    Name of a child, a hash of names, or a validator function.

    Returns

    node
  • getHtml() → String

    since 4.3.0

    Gets this element's inner HTML.

    Returns

    String
  • getIndex() → Number

    since 4.3.0 inherited

    Gets this node's index in its parent's children array.

    Returns

    Number
  • getOuterHtml() → String

    since 4.3.0

    Gets this element's outer HTML.

    Returns

    String
  • hasClass( className ) → Boolean

    since 4.3.0

    Checkes whether this element has a class name.

    Parameters

    className : String

    The class name to be checked.

    Returns

    Boolean

    Whether this element has a className.

  • insertAfter( node )

    since 4.1.0 inherited

    Insert this node after given one.

    Parameters

    node : node

    The node that will precede this element.

  • insertBefore( node )

    since 4.1.0 inherited

    Insert this node before given one.

    Parameters

    node : node

    The node that will follow this element.

  • remove()

    since 4.1.0 inherited

    Remove this node from a tree.

  • removeClass( className )

    since 4.3.0

    Removes a class name from the list of classes.

    Parameters

    className : String

    The class name to be removed.

  • replaceWith( node )

    since 4.1.0 inherited

    Replace this node with given one.

    Parameters

    node : node

    The node that will replace this one.

  • replaceWithChildren()

    since 4.1.0

    Replaces this element with its children.

  • setHtml( html )

    since 4.3.0

    Sets this element's inner HTML.

    Parameters

    html : String
  • split( index ) → element

    since 4.3.0

    Splits this element at the given index.

    Parameters

    index : Number

    Index at which the element will be split — 0 means the beginning, 1 after the first child node, etc.

    Returns

    element

    The new element following this one.

  • wrapWith( wrapper ) → element

    since 4.3.0 inherited

    Wraps this element with given wrapper.

    Parameters

    wrapper : element

    The element which will be this element's new parent.

    Returns

    element

    Wrapper.

  • writeChildrenHtml( writer, [ filter ] )

    Sends children of this element to the writer.

    Parameters

    writer : basicWriter

    The writer to which HTML will be written.

    [ filter ] : filter
  • writeHtml( writer, [ filter ] )

    Writes the element HTML to the CKEDITOR.htmlWriter.

    Parameters

    writer : basicWriter

    The writer to which HTML will be written.

    [ filter ] : filter

    The filter to be applied to this node. Note: It is unsafe to filter an offline (not appended) node.