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.

  • readonly

    type : Number

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

    Defaults to CKEDITOR.NODE_ELEMENT

  • private

    _ : Object

Methods

  • inherited

    constructor() → node

    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.

  • since 4.4.0

    addClass( className )

    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.

  • since 4.1.0

    filter( filter ) → Boolean

    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.

  • since 4.1.0

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

    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.

    [ type ] : Number

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

    [ skipRoot ] : Boolean

    Do not execute callback on this element.

  • since 4.3.0 inherited

    getAscendant( condition ) → element

    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.

  • since 4.3.0

    getFirst( condition ) → node

    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
  • since 4.3.0

    getHtml() → String

    Gets this element's inner HTML.

    Returns

    String
  • since 4.3.0 inherited

    getIndex() → Number

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

    Returns

    Number
  • since 4.3.0

    getOuterHtml() → String

    Gets this element's outer HTML.

    Returns

    String
  • since 4.3.0

    hasClass( className ) → Boolean

    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.

  • since 4.1.0 inherited

    insertAfter( node )

    Insert this node after given one.

    Parameters

    node : node

    The node that will precede this element.

  • since 4.1.0 inherited

    insertBefore( node )

    Insert this node before given one.

    Parameters

    node : node

    The node that will follow this element.

  • since 4.1.0 inherited

    remove()

    Remove this node from a tree.

  • since 4.3.0

    removeClass( className )

    Removes a class name from the list of classes.

    Parameters

    className : String

    The class name to be removed.

  • since 4.1.0 inherited

    replaceWith( node )

    Replace this node with given one.

    Parameters

    node : node

    The node that will replace this one.

  • since 4.1.0

    replaceWithChildren()

    Replaces this element with its children.

  • since 4.3.0

    setHtml( html )

    Sets this element's inner HTML.

    Parameters

    html : String
  • since 4.3.0

    split( index ) → element

    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.

  • since 4.3.0 inherited

    wrapWith( wrapper ) → element

    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.