CKEDITOR.htmlParser.element
A lightweight representation of an HTML element.
Filtering
Properties
attributes : ObjectCKEDITOR.htmlParser.element#attributesStores the attributes defined for this element.
children : ArrayCKEDITOR.htmlParser.element#childrenname : StringCKEDITOR.htmlParser.element#nameThe 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#addAdds a node to the element children list.
Parameters
node : nodeThe node to be added.
[ index ] : NumberFrom where the insertion happens.
-
Adds a class name to the list of classes.
Parameters
className : StringThe class name to be added.
clone() → elementCKEDITOR.htmlParser.element#clone-
Filters this element and its children with the given filter.
Parameters
filter : filter
Returns
BooleanThe method returns
falsewhen 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#filterChildrenFilters 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#findSearches through the current node children to find nodes matching the
criteria.Parameters
criteria : String | FunctionTag name or evaluator function.
[ recursive ] : BooleanDefaults to
false
Returns
node[]
findOne( criteria, [ recursive ] ) → node | nullCKEDITOR.htmlParser.element#findOneSearches 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 | FunctionTag name or evaluator function.
[ recursive ] : BooleanIf set to
true, it will iterate over all descendants. Otherwise the method will only iterate over direct children.Defaults to
false
Returns
node | nullThe first matched child,
nullotherwise.
-
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 : FunctionFunction to be executed on every node. Since 4.3: If
callbackreturnedfalse, the descendants of the current node will be ignored.[ type ] : NumberWhether the specified
callbackwill be executed only on nodes of this type.[ skipRoot ] : BooleanDo not execute
callbackon this element.
-
Gets the closest ancestor element of this element which satisfies given condition
Parameters
condition : String | Object | FunctionName of an ancestor, hash of names or validator function.
Returns
elementThe closest ancestor which satisfies given condition or
null.
-
Gets this element's first child. If
conditionis given, this method returns the first child which satisfies that condition.Parameters
condition : String | Object | FunctionName of a child, a hash of names, or a validator function.
Returns
node
-
-
-
-
Checkes whether this element has a class name.
Parameters
className : StringThe class name to be checked.
Returns
BooleanWhether this element has a
className.
-
Insert this node after given one.
Parameters
node : nodeThe node that will precede this element.
-
Insert this node before given one.
Parameters
node : nodeThe node that will follow this element.
-
Remove this node from a tree.
-
Removes a class name from the list of classes.
Parameters
className : StringThe class name to be removed.
-
Replace this node with given one.
Parameters
node : nodeThe node that will replace this one.
-
Replaces this element with its children.
-
-
Splits this element at the given index.
Parameters
index : NumberIndex at which the element will be split —
0means the beginning,1after the first child node, etc.
Returns
elementThe new element following this one.
-
Wraps this element with given
wrapper.Parameters
wrapper : elementThe element which will be this element's new parent.
Returns
elementWrapper.
writeChildrenHtml( writer, [ filter ] )CKEDITOR.htmlParser.element#writeChildrenHtmlSends children of this element to the writer.
Parameters
writer : basicWriterThe writer to which HTML will be written.
[ filter ] : filter
writeHtml( writer, [ filter ] )CKEDITOR.htmlParser.element#writeHtmlWrites the element HTML to the CKEDITOR.htmlWriter.
Parameters
writer : basicWriterThe writer to which HTML will be written.
[ filter ] : filterThe filter to be applied to this node. Note: It is unsafe to filter an offline (not appended) node.