CKEditor 4 Documentation

CKEDITOR.dom.node

Hierarchy

CKEDITOR.dom.domObject
CKEDITOR.dom.node

Inherited mixins

Subclasses

Files

Base class for classes representing DOM nodes. This constructor may return an instance of a class that inherits from this class, like CKEDITOR.dom.element or CKEDITOR.dom.text.

Defined By

Properties

The native DOM object represented by this class instance. ...

The native DOM object represented by this class instance.

var element = new CKEDITOR.dom.element( 'span' );
alert( element.$.nodeType ); // '1'
Defined By

Methods

CKEDITOR.dom.node
view source
new( domNode ) : CKEDITOR.dom.node
Creates a node class instance. ...

Creates a node class instance.

Parameters

Returns

Overrides: CKEDITOR.dom.domObject.constructor

CKEDITOR.dom.node
view source
( element ) : CKEDITOR.dom.element
Makes this node a child of another element. ...

Makes this node a child of another element.

var p = new CKEDITOR.dom.element( 'p' );
var strong = new CKEDITOR.dom.element( 'strong' );
strong.appendTo( p );

// Result: '<p><strong></strong></p>'.

Parameters

Returns

Register event handler under the capturing stage on supported target. ...

Register event handler under the capturing stage on supported target.

Removes any data stored on this object. ...

Removes any data stored on this object. To avoid memory leaks we must assure that there are no references left after the object is no longer needed.

CKEDITOR.dom.node
view source
( [includeChildren], [cloneId] ) : CKEDITOR.dom.node
Clone this node. ...

Clone this node.

Note: Values set by {setCustomData} won't be available in the clone.

Parameters

  • includeChildren : Boolean (optional)

    If true then all node's children will be cloned recursively.

    Defaults to: false

  • cloneId : Boolean (optional)

    Whether ID attributes should be cloned too.

    Defaults to: false

Returns

Predefine some intrinsic properties on a specific event name. ...

Predefine some intrinsic properties on a specific event name.

Parameters

  • name : String

    The event name

  • meta : Object
    • errorProof : (optional)

      Whether the event firing should catch error thrown from a per listener call.

      Defaults to: false

Determines whether the specified object is equal to the current object. ...

Determines whether the specified object is equal to the current object.

var doc = new CKEDITOR.dom.document( document );
alert( doc.equals( CKEDITOR.document ) );   // true
alert( doc == CKEDITOR.document );          // false

Parameters

  • object : Object

    The object to compare with the current object.

Returns

  • Boolean

    true if the object is equal.

( eventName, [data], [editor] ) : Boolean/Object
Fires an specific event in the object. ...

Fires an specific event in the object. All registered listeners are called at this point.

someObject.on( 'someEvent', function() { ... } );
someObject.on( 'someEvent', function() { ... } );
someObject.fire( 'someEvent' );             // Both listeners are called.

someObject.on( 'someEvent', function( event ) {
    alert( event.data );                    // 'Example'
} );
someObject.fire( 'someEvent', 'Example' );

Parameters

Returns

  • Boolean/Object

    A boolean indicating that the event is to be canceled, or data returned by one of the listeners.

( eventName, [data], [editor] ) : Boolean/Object
Fires an specific event in the object, releasing all listeners registered to that event. ...

Fires an specific event in the object, releasing all listeners registered to that event. The same listeners are not called again on successive calls of it or of fire.

someObject.on( 'someEvent', function() { ... } );
someObject.fire( 'someEvent' );         // Above listener called.
someObject.fireOnce( 'someEvent' );     // Above listener called.
someObject.fire( 'someEvent' );         // No listeners called.

Parameters

Returns

  • Boolean/Object

    A booloan indicating that the event is to be canceled, or data returned by one of the listeners.

CKEDITOR.dom.node
view source
( [normalized] ) : Array
Retrieves a uniquely identifiable tree address for this node. ...

Retrieves a uniquely identifiable tree address for this node. The tree address returned is an array of integers, with each integer indicating a child index of a DOM node, starting from document.documentElement.

For example, assuming <body> is the second child of <html> (<head> being the first), and we would like to address the third child under the fourth child of <body>, the tree address returned would be: [1, 3, 2].

The tree address cannot be used for finding back the DOM tree node once the DOM tree structure has been modified.

Parameters

  • normalized : Boolean (optional)

    See getIndex.

    Defaults to: false

Returns

  • Array

    The address.

CKEDITOR.dom.node
view source
( reference, [includeSelf] ) : CKEDITOR.dom.node
Gets the closest ancestor node of this node, specified by its name. ...

Gets the closest ancestor node of this node, specified by its name.

// Suppose we have the following HTML structure:
// <div id="outer"><div id="inner"><p><b>Some text</b></p></div></div>
// If node == <b>
ascendant = node.getAscendant( 'div' );             // ascendant == <div id="inner">
ascendant = node.getAscendant( 'b' );               // ascendant == null
ascendant = node.getAscendant( 'b', true );         // ascendant == <b>
ascendant = node.getAscendant( { div:1,p:1 } );     // Searches for the first 'div' or 'p': ascendant == <div id="inner">

Available since: 3.6.1

Parameters

  • reference : String

    The name of the ancestor node to search or an object with the node names to search for.

  • includeSelf : Boolean (optional)

    Whether to include the current node in the search.

Returns

CKEDITOR.dom.node
view source
( node )
...

Parameters

  • node : Object
Gets the value set to a data slot in this object. ...

Gets the value set to a data slot in this object.

var element = new CKEDITOR.dom.element( 'span' );
alert( element.getCustomData( 'hasCustomData' ) );      // e.g. 'true'
alert( element.getCustomData( 'nonExistingKey' ) );     // null

Parameters

  • key : String

    The key used to identify the data slot.

Returns

  • Object

    This value set to the data slot.

Gets the document containing this element. ...

Gets the document containing this element.

var element = CKEDITOR.document.getById( 'example' );
alert( element.getDocument().equals( CKEDITOR.document ) ); // true

Returns

CKEDITOR.dom.node
view source
( normalized ) : Number
Get index of a node in an array of its parent.childNodes. ...

Get index of a node in an array of its parent.childNodes.

Let's assume having childNodes array:

[ emptyText, element1, text, text, element2 ]
element1.getIndex();        // 1
element1.getIndex( true );  // 0
element2.getIndex();        // 4
element2.getIndex( true );  // 2

Parameters

  • normalized : Boolean

    When true empty text nodes and one followed by another one text node are not counted in.

Returns

  • Number

    Index of a node.

CKEDITOR.dom.node
view source
( [evaluator] ) : CKEDITOR.dom.node
Gets the node that follows this element in its parent's child list. ...

Gets the node that follows this element in its parent's child list.

var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b><i>next</i></div>' );
var last = element.getFirst().getNext();
alert( last.getName() ); // 'i'

Parameters

  • evaluator : Function (optional)

    Filtering the result node.

Returns

CKEDITOR.dom.node
view source
( startFromSibling, nodeType, guard )
...

Parameters

  • startFromSibling : Object
  • nodeType : Object
  • guard : Object
CKEDITOR.dom.node
view source
( [allowFragmentParent] ) : CKEDITOR.dom.element
Gets the parent element for this node. ...

Gets the parent element for this node.

var node = editor.document.getBody().getFirst();
var parent = node.getParent();
alert( parent.getName() ); // 'body'

Parameters

Returns

CKEDITOR.dom.node
view source
( [closerFirst] ) : Array
Returns array containing node parents and node itself. ...

Returns array containing node parents and node itself. By default nodes are in descending order.

// Assuming that body has paragraph as first child.
var node = editor.document.getBody().getFirst();
var parents = node.getParents();
alert( parents[ 0 ].getName() + ',' + parents[ 2 ].getName() ); // 'html,p'

Parameters

  • closerFirst : Boolean (optional)

    Determines order of returned nodes.

    Defaults to: false

Returns

CKEDITOR.dom.node
view source
( otherNode )
...

Parameters

  • otherNode : Object
CKEDITOR.dom.node
view source
( [evaluator] ) : CKEDITOR.dom.node
Gets the node that preceed this element in its parent's child list. ...

Gets the node that preceed this element in its parent's child list.

var element = CKEDITOR.dom.element.createFromHtml( '<div><i>prev</i><b>Example</b></div>' );
var first = element.getLast().getPrev();
alert( first.getName() ); // 'i'

Parameters

  • evaluator : Function (optional)

    Filtering the result node.

Returns

CKEDITOR.dom.node
view source
( startFromSibling, nodeType, guard )
...

Parameters

  • startFromSibling : Object
  • nodeType : Object
  • guard : Object
Get the private _ object which is bound to the native DOM object using getCustomData. ...

Get the private _ object which is bound to the native DOM object using getCustomData.

var elementA = new CKEDITOR.dom.element( nativeElement );
elementA.getPrivate().value = 1;
...
var elementB = new CKEDITOR.dom.element( nativeElement );
elementB.getPrivate().value; // 1

Returns

  • Object

    The private object.

Gets an ID that can be used to identiquely identify this DOM object in the running session. ...

Gets an ID that can be used to identiquely identify this DOM object in the running session.

Returns

  • Number

    A unique ID.

CKEDITOR.dom.node
view source
( name, includeSelf )
...

Parameters

  • name : Object
  • includeSelf : Object
Checks if there is any listener registered to a given event. ...

Checks if there is any listener registered to a given event.

var myListener = function() { ... };
someObject.on( 'someEvent', myListener );
alert( someObject.hasListeners( 'someEvent' ) );    // true
alert( someObject.hasListeners( 'noEvent' ) );      // false

Parameters

  • eventName : String

    The event name.

Returns

  • Boolean
CKEDITOR.dom.node
view source
( ) : Boolean
Check if node is succeeded by any sibling. ...

Check if node is succeeded by any sibling.

Returns

  • Boolean
CKEDITOR.dom.node
view source
( ) : Boolean
Check if node is preceded by any sibling. ...

Check if node is preceded by any sibling.

Returns

  • Boolean
CKEDITOR.dom.node
view source
( node ) : CKEDITOR.dom.node
Inserts this element after a node. ...

Inserts this element after a node.

var em = new CKEDITOR.dom.element( 'em' );
var strong = new CKEDITOR.dom.element( 'strong' );
strong.insertAfter( em );

// Result: '<em></em><strong></strong>'

Parameters

Returns

CKEDITOR.dom.node
view source
( node ) : CKEDITOR.dom.node
Inserts this element before a node. ...

Inserts this element before a node.

var em = new CKEDITOR.dom.element( 'em' );
var strong = new CKEDITOR.dom.element( 'strong' );
strong.insertBefore( em );

// result: '<strong></strong><em></em>'

Parameters

Returns

CKEDITOR.dom.node
view source
( node ) : CKEDITOR.dom.node
Inserts node before this node. ...

Inserts node before this node.

var em = new CKEDITOR.dom.element( 'em' );
var strong = new CKEDITOR.dom.element( 'strong' );
strong.insertBeforeMe( em );

// result: '<em></em><strong></strong>'

Parameters

Returns

CKEDITOR.dom.node
view source
( ) : Boolean
Checks if this node is read-only (should not be changed). ...

Checks if this node is read-only (should not be changed).

Note: When attributeCheck is not used, this method only work for elements that are already presented in the document, otherwise the result is not guaranteed, it's mainly for performance consideration.

// For the following HTML:
// <div contenteditable="false">Some <b>text</b></div>

// If "ele" is the above <div>
element.isReadOnly(); // true

Available since: 3.5

Returns

  • Boolean
CKEDITOR.dom.node
view source
( )
...
CKEDITOR.dom.node
view source
( target, toStart )
...

Parameters

  • target : Object
  • toStart : Object
( eventName, listenerFunction, [scopeObj], [listenerData], [priority] ) : Object
Registers a listener to a specific event in the current object. ...

Registers a listener to a specific event in the current object.

someObject.on( 'someEvent', function() {
    alert( this == someObject );        // true
} );

someObject.on( 'someEvent', function() {
    alert( this == anotherObject );     // true
}, anotherObject );

someObject.on( 'someEvent', function( event ) {
    alert( event.listenerData );        // 'Example'
}, null, 'Example' );

someObject.on( 'someEvent', function() { ... } );                       // 2nd called
someObject.on( 'someEvent', function() { ... }, null, null, 100 );      // 3rd called
someObject.on( 'someEvent', function() { ... }, null, null, 1 );        // 1st called

Parameters

  • eventName : String

    The event name to which listen.

  • listenerFunction : Function

    The function listening to the event. A single CKEDITOR.eventInfo object instanced is passed to this function containing all the event data.

  • scopeObj : Object (optional)

    The object used to scope the listener call (the this object). If omitted, the current object is used.

  • listenerData : Object (optional)

    Data to be sent as the CKEDITOR.eventInfo.listenerData when calling the listener.

  • priority : Number (optional)

    The listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.

    Defaults to: 10

Returns

  • Object

    An object containing the removeListener function, which can be used to remove the listener at any time.

Similiar with on but the listener will be called only once upon the next event firing. ...

Similiar with on but the listener will be called only once upon the next event firing.

CKEDITOR.event.on

CKEDITOR.dom.node
view source
( [preserveChildren] ) : CKEDITOR.dom.nodechainable
Removes this node from the document DOM. ...

Removes this node from the document DOM.

var element = CKEDITOR.document.getById( 'MyElement' );
element.remove();

Parameters

  • preserveChildren : Boolean (optional)

    Indicates that the children elements must remain in the document, removing only the outer tags.

    Defaults to: false

Returns

Removes any listener set on this object. ...

Removes any listener set on this object.

To avoid memory leaks we must assure that there are no references left after the object is no longer needed.

Overrides: CKEDITOR.event.removeAllListeners

Removes the value in data slot under given key. ...

Removes the value in data slot under given key.

Parameters

  • key : String

Returns

  • Object

    Removed value or null if not found.

( eventName, listenerFunction )
Unregisters a listener function from being called at the specified event. ...

Unregisters a listener function from being called at the specified event. No errors are thrown if the listener has not been registered previously.

var myListener = function() { ... };
someObject.on( 'someEvent', myListener );
someObject.fire( 'someEvent' );                 // myListener called.
someObject.removeListener( 'someEvent', myListener );
someObject.fire( 'someEvent' );                 // myListener not called.

Parameters

  • eventName : String

    The event name.

  • listenerFunction : Function

    The listener function to unregister.

CKEDITOR.dom.node
view source
( nodeToReplace )
...

Parameters

  • nodeToReplace : Object
CKEDITOR.dom.node
view source
( )
...
Sets a data slot value for this object. ...

Sets a data slot value for this object. These values are shared by all instances pointing to that same DOM object.

Note: The created data slot is only guarantied to be available on this unique dom node, thus any wish to continue access it from other element clones (either created by clone node or from innerHtml) will fail, for such usage, please use CKEDITOR.dom.element.setAttribute instead.

var element = new CKEDITOR.dom.element( 'span' );
element.setCustomData( 'hasCustomData', true );

Parameters

  • key : String

    A key used to identify the data slot.

  • value : Object

    The value to set to the data slot.

Returns

CKEDITOR.dom.node
view source
( )
...