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
The nodes that are direct children of this element.
Defaults to
[]
-
name : String
CKEDITOR.htmlParser.element#name
The element name.
-
type : Number
CKEDITOR.htmlParser.element#type
readonly
The node type. This is a constant value set to CKEDITOR.NODE_ELEMENT.
Defaults to
CKEDITOR.NODE_ELEMENT
-
_ : Object
CKEDITOR.htmlParser.element#_
private
Methods
-
constructor() → node
CKEDITOR.htmlParser.element#constructor
inherited
Creates a node class instance.
Returns
-
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.
-
addClass( className )
CKEDITOR.htmlParser.element#addClass
since 4.4.0
Adds a class name to the list of classes.
Parameters
className : String
The class name to be added.
-
Clones this element.
Returns
element
The element clone.
-
filter( filter ) → Boolean
CKEDITOR.htmlParser.element#filter
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 )
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
-
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[]
-
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 ] )
CKEDITOR.htmlParser.element#forEach
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
returnedfalse
, the descendants of the current node will be ignored.Propertiesnode : 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
CKEDITOR.htmlParser.element#getAscendant
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
.
-
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
-
getHtml() → String
CKEDITOR.htmlParser.element#getHtml
since 4.3.0
Gets this element's inner HTML.
Returns
String
-
getIndex() → Number
CKEDITOR.htmlParser.element#getIndex
since 4.3.0 inherited
Gets this node's index in its parent's children array.
Returns
Number
-
getOuterHtml() → String
CKEDITOR.htmlParser.element#getOuterHtml
since 4.3.0
Gets this element's outer HTML.
Returns
String
-
hasClass( className ) → Boolean
CKEDITOR.htmlParser.element#hasClass
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 )
CKEDITOR.htmlParser.element#insertAfter
since 4.1.0 inherited
Insert this node after given one.
Parameters
node : node
The node that will precede this element.
-
insertBefore( node )
CKEDITOR.htmlParser.element#insertBefore
since 4.1.0 inherited
Insert this node before given one.
Parameters
node : node
The node that will follow this element.
-
remove()
CKEDITOR.htmlParser.element#remove
since 4.1.0 inherited
Remove this node from a tree.
-
removeClass( className )
CKEDITOR.htmlParser.element#removeClass
since 4.3.0
Removes a class name from the list of classes.
Parameters
className : String
The class name to be removed.
-
replaceWith( node )
CKEDITOR.htmlParser.element#replaceWith
since 4.1.0 inherited
Replace this node with given one.
Parameters
node : node
The node that will replace this one.
-
replaceWithChildren()
CKEDITOR.htmlParser.element#replaceWithChildren
since 4.1.0
Replaces this element with its children.
-
setHtml( html )
CKEDITOR.htmlParser.element#setHtml
since 4.3.0
Sets this element's inner HTML.
Parameters
html : String
-
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
. -
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.