CKEDITOR.htmlParser.element
A lightweight representation of an HTML element.
Filtering
Properties
-
attributes : Object
CKEDITOR.htmlParser.element#attributes
Stores the attributes defined for this element.
-
children : Array
CKEDITOR.htmlParser.element#children
-
name : String
CKEDITOR.htmlParser.element#name
The element name.
-
The node type. This is a constant value set to CKEDITOR.NODE_ELEMENT.
Defaults to
CKEDITOR.NODE_ELEMENT
Methods
-
-
add( node, [ index ] )
CKEDITOR.htmlParser.element#add
Adds a node to the element children list.
Parameters
node : node
The node to be added.
[ index ] : Number
From where the insertion happens.
-
Adds a class name to the list of classes.
Parameters
className : String
The class name to be added.
-
clone() → element
CKEDITOR.htmlParser.element#clone
-
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 )
CKEDITOR.htmlParser.element#filterChildren
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[]
CKEDITOR.htmlParser.element#find
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
CKEDITOR.htmlParser.element#findOne
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.
-
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
returnedfalse
, 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.
-
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
.
-
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
-
-
-
-
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
.
-
Insert this node after given one.
Parameters
node : node
The node that will precede this element.
-
Insert this node before given one.
Parameters
node : node
The node that will follow this element.
-
Remove this node from a tree.
-
Removes a class name from the list of classes.
Parameters
className : String
The class name to be removed.
-
Replace this node with given one.
Parameters
node : node
The node that will replace this one.
-
Replaces this element with its children.
-
-
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.
-
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 ] )
CKEDITOR.htmlParser.element#writeChildrenHtml
Sends children of this element to the writer.
Parameters
writer : basicWriter
The writer to which HTML will be written.
[ filter ] : filter
-
writeHtml( writer, [ filter ] )
CKEDITOR.htmlParser.element#writeHtml
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.