CKEDITOR.dom.element
Represents a DOM element.
// Create a new <span> element.
var element = new CKEDITOR.dom.element( 'span' );
// Create an element based on a native DOM element.
var element = new CKEDITOR.dom.element( document.getElementById( 'myId' ) );
Filtering
Properties
-
The native DOM object represented by this class instance.
var element = new CKEDITOR.dom.element( 'span' ); alert( element.$.nodeType ); // '1' -
The node type. This is a constant value set to CKEDITOR.NODE_ELEMENT.
Defaults to
CKEDITOR.NODE_ELEMENT
Static properties
Methods
-
Creates a domObject class instance.
Parameters
nativeDomObject : ObjectA native DOM object.
Returns
domObject
-
Adds a CSS class to the element. It appends the class to the already existing names.
var element = new CKEDITOR.dom.element( 'div' ); element.addClass( 'classA' ); // <div class="classA"> element.addClass( 'classB' ); // <div class="classA classB"> element.addClass( 'classA' ); // <div class="classA classB">Note: Since CKEditor 4.5.0 this method cannot be used with multiple classes (
'classA classB').Parameters
className : StringThe name of the class to be added.
Returns
elementthis
append( node, [ toStart ] ) → nodeCKEDITOR.dom.element#appendAppend a node as a child of this element.
var p = new CKEDITOR.dom.element( 'p' ); var strong = new CKEDITOR.dom.element( 'strong' ); p.append( strong ); var em = p.append( 'em' ); // Result: '<p><strong></strong><em></em></p>'Parameters
node : node | StringThe node or element name to be appended.
[ toStart ] : BooleanIndicates that the element is to be appended at the start.
Defaults to
false
Returns
nodeThe appended node.
appendBogus( [ force ] )CKEDITOR.dom.element#appendBogusAppends a
<br>filler element to this element if the filler is not present already. By default filler is appended only if CKEDITOR.env.needsBrFiller istrue, however whenforceis set totruefiller will be appended regardless of the environment.Parameters
[ force ] : BooleanAppend filler regardless of the environment.
appendHtml( html )CKEDITOR.dom.element#appendHtmlappendText( text )CKEDITOR.dom.element#appendTextAppend text to this element.
var p = new CKEDITOR.dom.element( 'p' ); p.appendText( 'This is' ); p.appendText( ' some text' ); // Result: '<p>This is some text</p>'Parameters
text : StringThe text to be appended.
-
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
element : elementThe target element to which this node will be appended.
Returns
elementThe target element.
breakParent( parent, [ cloneId ] )CKEDITOR.dom.element#breakParentBreaks one of the ancestor element in the element position, moving this element between the broken parts.
// Before breaking: // <b>This <i>is some<span /> sample</i> test text</b> // If "element" is <span /> and "parent" is <i>: // <b>This <i>is some</i><span /><i> sample</i> test text</b> element.breakParent( parent ); // Before breaking: // <b>This <i>is some<span /> sample</i> test text</b> // If "element" is <span /> and "parent" is <b>: // <b>This <i>is some</i></b><span /><b><i> sample</i> test text</b> element.breakParent( parent );Parameters
parent : elementThe anscestor element to get broken.
[ cloneId ] : BooleanWhether to preserve ancestor ID attributes while breaking.
Defaults to
false
-
Register event handler under the capturing stage on supported target.
-
Removes any data stored in this object. To avoid memory leaks we must assure that there are no references left after the object is no longer needed.
-
Clones this node.
Note: Values set by {setCustomData} will not be available in the clone.
Parameters
[ includeChildren ] : BooleanIf
truethen all node's children will be cloned recursively.Defaults to
false[ cloneId ] : BooleanWhether ID attributes should be cloned, too.
Defaults to
false
Returns
nodeClone of this node.
contains( node ) → BooleanCKEDITOR.dom.element#containscopyAttributes( dest, skipAttributes )CKEDITOR.dom.element#copyAttributesCopy all the attributes from one node to the other, kinda like a clone skipAttributes is an object with the attributes that must not be copied.
Parameters
dest : elementThe destination element.
skipAttributes : ObjectA dictionary of attributes to skip.
data( name, [ value ] )CKEDITOR.dom.element#dataGets, sets and removes custom data to be stored as HTML5 data-* attributes.
element.data( 'extra-info', 'test' ); // Appended the attribute data-extra-info="test" to the element. alert( element.data( 'extra-info' ) ); // 'test' element.data( 'extra-info', false ); // Remove the data-extra-info attribute from the element.Parameters
name : StringThe name of the attribute, excluding the
data-part.[ value ] : StringThe value to set. If set to false, the attribute will be removed.
-
Predefine some intrinsic properties on a specific event name.
Parameters
name : StringThe event name
meta : Object
disableContextMenu()CKEDITOR.dom.element#disableContextMenuDisables browser's context menu in this element.
-
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 ); // falseParameters
object : ObjectThe object to compare with the current object.
Returns
Booleantrueif the object is equal.
-
Returns list of elements within this element that match specified
selector.Notes:
- Not available in IE7.
- Returned list is not a live collection (like a result of native
querySelectorAll). Unlike the native
querySelectorAllthis method ensures selector contextualization. This is:HTML: '<body><div><i>foo</i></div></body>' Native: div.querySelectorAll( 'body i' ) // -> [ <i>foo</i> ] Method: div.find( 'body i' ) // -> [] div.find( 'i' ) // -> [ <i>foo</i> ]
Parameters
selector : StringA valid CSS selector.
Returns
nodeList
-
Returns the first element within this element that matches the specified
selector.Notes:
- Not available in IE7.
Unlike the native
querySelectorthis method ensures selector contextualization. This is:HTML: '<body><div><i>foo</i></div></body>' Native: div.querySelector( 'body i' ) // -> <i>foo</i> Method: div.findOne( 'body i' ) // -> null div.findOne( 'i' ) // -> <i>foo</i>
Parameters
selector : StringA valid CSS selector.
Returns
element
-
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
eventName : StringThe event name to fire.
[ data ] : ObjectData to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editorThe editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | ObjectA boolean indicating that the event is to be canceled, or data returned by one of the listeners.
-
Fires the element event handler attribute, for example:
<button onkeydown="return customFn( event )">x</button>buttonEl.fireEventHandler( 'keydown', { keyCode: 13 // Enter } );Parameters
element : element | HTMLElementAn element with an attached event handler attribute.
eventName : StringEvent name.
evt : ObjectEvent payload.
inherited
fireOnce( eventName, [ data ], [ editor ] ) → Boolean | ObjectCKEDITOR.dom.element#fireOnceFires 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
eventName : StringThe event name to fire.
[ data ] : ObjectData to be sent as the CKEDITOR.eventInfo.data when calling the listeners.
[ editor ] : editorThe editor instance to send as the CKEDITOR.eventInfo.editor when calling the listener.
Returns
Boolean | ObjectA booloan indicating that the event is to be canceled, or data returned by one of the listeners.
focus( defer )CKEDITOR.dom.element#focusMoves the selection focus to this element.
var element = CKEDITOR.document.getById( 'myTextarea' ); element.focus();Parameters
defer : BooleanWhether to asynchronously defer the execution by 100 ms.
focusNext( [ ignoreChildren ], [ indexToUse ] )CKEDITOR.dom.element#focusNextMoves the UI focus to the element following this element in the tabindex order.
var element = CKEDITOR.document.getById( 'example' ); element.focusNext();Parameters
[ ignoreChildren ] : BooleanDefaults to
false[ indexToUse ] : Number
focusPrevious( [ ignoreChildren ], [ indexToUse ] )CKEDITOR.dom.element#focusPreviousMoves the UI focus to the element before this element in the tabindex order.
var element = CKEDITOR.document.getById( 'example' ); element.focusPrevious();Parameters
[ ignoreChildren ] : BooleanDefaults to
false[ indexToUse ] : Number
-
Traverse the DOM of this element (inclusive), executing a callback for each node.
var element = CKEDITOR.dom.element.createFromHtml( '<div><p>foo<b>bar</b>bom</p></div>' ); element.forEach( function( node ) { console.log( node ); } ); // Will log: // 1. <div> element, // 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. If
callbackreturnsfalsedescendants of the node will be ignored.[ type ] : NumberIf specified
callbackwill be executed only on nodes of this type.[ skipRoot ] : BooleanDon't execute
callbackon this element.
-
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 ] : BooleanSee getIndex.
Defaults to
false
Returns
ArrayThe address.
-
Gets the closest ancestor node of this node, specified by its name or using an evaluator function.
// 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"> // Using custom evaluator: ascendant = node.getAscendant( function( el ) { return el.getId() == 'inner'; } ); // ascendant == <div id="inner">Parameters
query : String | Function | ObjectThe name of the ancestor node to search or an object with the node names to search for or an evaluator function.
[ includeSelf ] : BooleanWhether to include the current node in the search.
Returns
nodeThe located ancestor node or
nullif not found.
getAttribute( name ) → StringCKEDITOR.dom.element#getAttributeGets the value of an element attribute.
var element = CKEDITOR.dom.element.createFromHtml( '<input type="text" />' ); alert( element.getAttribute( 'type' ) ); // 'text'Parameters
name : StringThe attribute name.
Returns
StringThe attribute value or null if not defined.
getAttributes( exclude ) → ObjectCKEDITOR.dom.element#getAttributesGets the values of all element attributes.
Parameters
exclude : ArrayThe names of attributes to be excluded from the returned object.
Returns
ObjectAn object containing all element attributes with their values.
getBogus() → node | BooleanCKEDITOR.dom.element#getBogusChecks if there is a filler node at the end of an element, and returns it.
Returns
node | BooleanBogus node or
false.
getChild( indices ) → nodeCKEDITOR.dom.element#getChildGets a DOM tree descendant under the current node.
var strong = p.getChild( 0 );Parameters
indices : Array | NumberThe child index or array of child indices under the node.
Returns
nodeThe specified DOM child under the current node. Null if child does not exist.
getChildCount() → NumberCKEDITOR.dom.element#getChildCountgetChildren() → nodeListCKEDITOR.dom.element#getChildrengetClientRect( [ isAbsolute ] ) → rectCKEDITOR.dom.element#getClientRectRetrieve the bounding rectangle of the current element, in pixels, relative to the upper-left corner of the browser's client area.
Since 4.10.0 you can pass an additional parameter if the function should return an absolute element position that can be used for positioning elements inside scrollable areas.
For example, you can use this function with the editor's window frame to calculate the absolute rectangle of the visible area of the editor viewport. The retrieved absolute rectangle can be used to position elements like toolbars or notifications (elements outside the editor) to always keep them inside the editor viewport independently from the scroll position.
var frame = editor.window.getFrame(); frame.getClientRect( true );Parameters
[ isAbsolute ] : BooleanThe function will retrieve an absolute rectangle of the element, i.e. the position relative to the upper-left corner of the topmost viewport. This option is available since 4.10.0.
Defaults to
false
Returns
rectThe dimensions of the DOM element.
-
Gets the element
clientWidthandclientHeight.Returns
ObjectAn object containing the width and height values.
-
getComputedStyle( propertyName ) → StringCKEDITOR.dom.element#getComputedStyleGets the current computed value of one of the element CSS style properties.
var element = new CKEDITOR.dom.element( 'span' ); alert( element.getComputedStyle( 'display' ) ); // 'inline'Parameters
propertyName : StringThe style property name.
Returns
StringThe property value.
-
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' ) ); // nullParameters
key : StringThe key used to identify the data slot.
Returns
ObjectThis value set to the data slot.
getDirection( useComputed )CKEDITOR.dom.element#getDirectionGets element's direction. Supports both CSS
directionprop anddirattr.Parameters
useComputed : Object
-
Gets the document containing this element.
var element = CKEDITOR.document.getById( 'example' ); alert( element.getDocument().equals( CKEDITOR.document ) ); // trueReturns
documentThe document.
getDocumentPosition( [ refDocument ] ) → ObjectCKEDITOR.dom.element#getDocumentPositionGets this element's position in document.
Parameters
[ refDocument ] : document
Returns
ObjectElement's position.
Propertiesx : Numbery : NumberrefDocument
getDtd() → ObjectCKEDITOR.dom.element#getDtdGets the DTD entries for this element.
Returns
ObjectAn object containing the list of elements accepted by this element.
getEditor( [ optimized ] ) → editorCKEDITOR.dom.element#getEditorRetrieves an editor instance which is based on this element (if any). It basically loops over CKEDITOR.instances in search for an instance that uses the element.
var element = new CKEDITOR.dom.element( 'div' ); element.appendTo( CKEDITOR.document.getBody() ); CKEDITOR.replace( element ); alert( element.getEditor().name ); // 'editor1'By default this method considers only original DOM elements upon which the editor was created. Setting
optimizedparameter tofalsewill consider editor editable and its children.Parameters
[ optimized ] : BooleanIf set to
falseit will scan every editor editable.Defaults to
true
Returns
editorAn editor instance or null if nothing has been found.
getElementsByTag( tagName )CKEDITOR.dom.element#getElementsByTaggetFirst( evaluator ) → nodeCKEDITOR.dom.element#getFirstGets the first child node of this element.
var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b></div>' ); var first = element.getFirst(); alert( first.getName() ); // 'b'Parameters
evaluator : FunctionFiltering the result node.
Returns
nodeThe first child node or null if not available.
getFrameDocument() → documentCKEDITOR.dom.element#getFrameDocumentgetHtml() → StringCKEDITOR.dom.element#getHtmlGets the inner HTML of this element.
var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b></div>' ); alert( element.getHtml() ); // '<b>Example</b>'Returns
StringThe inner HTML of this element.
getId() → StringCKEDITOR.dom.element#getIdGets the value of the
idattribute of this element.var element = CKEDITOR.dom.element.createFromHtml( '<p id="myId"></p>' ); alert( element.getId() ); // 'myId'Returns
StringThe element id, or null if not available.
-
Gets the index of a node in an array of its
parent.childNodes. Returns-1if a node does not have a parent or when thenormalizedargument is set totrueand the text node is empty and will be removed during the normalization.Let us assume having the following
childNodesarray:[ emptyText, element1, text, text, element2, emptyText2 ] emptyText.getIndex() // 0 emptyText.getIndex( true ) // -1 element1.getIndex(); // 1 element1.getIndex( true ); // 0 element2.getIndex(); // 4 element2.getIndex( true ); // 2 emptyText2.getIndex(); // 5 emptyText2.getIndex( true ); // -1Parameters
normalized : BooleanWhen
true, adjacent text nodes are merged and empty text nodes are removed.
Returns
NumberIndex of a node or
-1if a node does not have a parent or is removed during the normalization.
getLast( evaluator ) → nodeCKEDITOR.dom.element#getLastgetName() → StringCKEDITOR.dom.element#getNameGets the element name (tag name). The returned name is guaranteed to be always full lowercased.
var element = new CKEDITOR.dom.element( 'span' ); alert( element.getName() ); // 'span'Returns
StringThe element name.
getNameAtt() → StringCKEDITOR.dom.element#getNameAttGets the value of the
nameattribute of this element.var element = CKEDITOR.dom.element.createFromHtml( '<input name="myName"></input>' ); alert( <b>element.getNameAtt()</b> ); // 'myName'Returns
StringThe element name, or null if not available.
-
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 ] : FunctionFiltering the result node.
Returns
nodeThe next node or null if not available.
inherited
getNextSourceNode( startFromSibling, nodeType, guard )CKEDITOR.dom.element#getNextSourceNodegetOuterHtml() → StringCKEDITOR.dom.element#getOuterHtmlGets the outer (inner plus tags) HTML of this element.
var element = CKEDITOR.dom.element.createFromHtml( '<div class="bold"><b>Example</b></div>' ); alert( element.getOuterHtml() ); // '<div class="bold"><b>Example</b></div>'Returns
StringThe outer HTML of this element.
-
Gets the parent element for this node.
var node = editor.document.getBody().getFirst(); var parent = node.getParent(); alert( parent.getName() ); // 'body'Parameters
[ allowFragmentParent ] : BooleanConsider also parent node that is of fragment type CKEDITOR.NODE_DOCUMENT_FRAGMENT.
Defaults to
false
Returns
elementThe parent element.
-
Returns an array containing node parents and the node itself. By default nodes are in descending order.
// Assuming that body has paragraph as the first child. var node = editor.document.getBody().getFirst(); var parents = node.getParents(); alert( parents[ 0 ].getName() + ',' + parents[ 2 ].getName() ); // 'html,p'Parameters
[ closerFirst ] : BooleanDetermines the order of returned nodes.
Defaults to
false
Returns
ArrayReturns an array of CKEDITOR.dom.node.
-
Determines the position relation between this node and the given CKEDITOR.dom.node in the document. This node can be preceding (CKEDITOR.POSITION_PRECEDING) or following (CKEDITOR.POSITION_FOLLOWING) the given node. This node can also contain (CKEDITOR.POSITION_CONTAINS) or be contained by (CKEDITOR.POSITION_IS_CONTAINED) the given node. The function returns a bitmask of constants listed above or CKEDITOR.POSITION_IDENTICAL if the given node is the same as this node.
Parameters
otherNode : nodeA node to check relation with.
Returns
NumberPosition relation between this node and given node.
getPositionedAncestor() → elementCKEDITOR.dom.element#getPositionedAncestorGets closest positioned (
position != static) ancestor.Returns
elementPositioned ancestor or
null.
-
Gets the node that preceeds 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 ] : FunctionFiltering the result node.
Returns
nodeThe previous node or null if not available.
inherited
getPreviousSourceNode( startFromSibling, nodeType, guard )CKEDITOR.dom.element#getPreviousSourceNode-
Gets 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; // 1Returns
ObjectThe private object.
getSize( type, isBorderBox )CKEDITOR.dom.element#getSizeGets the element size, possibly considering the box model.
Parameters
type : 'width' | 'height'The dimension to get.
isBorderBox : BooleanGet the size based on the border box model.
getStyle( name ) → StringCKEDITOR.dom.element#getStyleGets CSS style value.
Parameters
name : StringThe CSS property name.
Returns
StringStyle value.
getTabIndex() → NumberCKEDITOR.dom.element#getTabIndexGets the computed tabindex for this element.
var element = CKEDITOR.document.getById( 'myDiv' ); alert( element.getTabIndex() ); // (e.g.) '-1'Returns
NumberThe tabindex value.
getText() → StringCKEDITOR.dom.element#getTextGets the text value of this element.
Only in IE (which uses innerText),
<br>will cause linebreaks, and sucessive whitespaces (including line breaks) will be reduced to a single space. This behavior is ok for us, for now. It may change in the future.var element = CKEDITOR.dom.element.createFromHtml( '<div>Sample <i>text</i>.</div>' ); alert( <b>element.getText()</b> ); // 'Sample text.'Returns
StringThe text value.
-
Gets an ID that can be used to identify this DOM object in the running session.
Note: This method does not work on text nodes prior to Internet Explorer 9.
Returns
NumberA unique ID.
getValue() → StringCKEDITOR.dom.element#getValueGets the value set to this element. This value is usually available for form field elements.
Returns
StringThe element value.
getWindow() → windowCKEDITOR.dom.element#getWindow-
hasAttribute( name ) → BooleanCKEDITOR.dom.element#hasAttributeChecks if the specified attribute is defined for this element.
Parameters
name : StringThe attribute name.
Returns
Booleantrueif the specified attribute is defined.
hasAttributes() → BooleanCKEDITOR.dom.element#hasAttributesChecks if the element has any defined attributes.
var element = CKEDITOR.dom.element.createFromHtml( '<div title="Test">Example</div>' ); alert( element.hasAttributes() ); // true var element = CKEDITOR.dom.element.createFromHtml( '<div>Example</div>' ); alert( element.hasAttributes() ); // falseReturns
BooleanTrue if the element has attributes.
hasClass( className ) → BooleanCKEDITOR.dom.element#hasClass-
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' ) ); // falseParameters
eventName : StringThe event name.
Returns
Boolean
-
-
hide()CKEDITOR.dom.element#hideHides this element (sets
display: none).var element = CKEDITOR.document.getById( 'myElement' ); element.hide();-
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
node : nodeThe node that will precede this element.
Returns
nodeThe node preceding this one after insertion.
-
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
node : nodeThe node that will succeed this element.
Returns
nodeThe node being inserted.
-
Inserts a 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
node : nodeThe node that will preceed this element.
Returns
nodeThe node being inserted.
is( name ) → BooleanCKEDITOR.dom.element#isChecks if the element name matches the specified criteria.
var element = new CKEDITOR.element( 'span' ); alert( element.is( 'span' ) ); // true alert( element.is( 'p', 'span' ) ); // true alert( element.is( 'p' ) ); // false alert( element.is( 'p', 'div' ) ); // false alert( element.is( { p:1,span:1 } ) ); // trueParameters
name : String | ObjectOne or more names to be checked, or a CKEDITOR.dtd object.
Returns
Booleantrueif the element name matches any of the names.
isBlockBoundary( [ customNodeNames ] ) → BooleanCKEDITOR.dom.element#isBlockBoundaryChecks whether an element is displayed as a block.
Parameters
[ customNodeNames ] : ObjectCustom list of nodes which will extend the default CKEDITOR.dtd.$block list.
Returns
Boolean
-
Checks if an element is detached from the DOM.
Returns
BooleanWhether an element is detached from the DOM.
isEditable( [ textCursor ] )CKEDITOR.dom.element#isEditableDecide whether one element is able to receive cursor.
Parameters
[ textCursor ] : BooleanOnly consider element that could receive text child.
Defaults to
true
isEmptyInlineRemoveable() → BooleanCKEDITOR.dom.element#isEmptyInlineRemoveableWhether it's an empty inline elements which has no visual impact when removed.
Returns
Boolean
isIdentical( otherElement ) → BooleanCKEDITOR.dom.element#isIdenticalCompare this element's inner html, tag name, attributes, etc. with other one.
See W3C's DOM Level 3 spec - node#isEqualNode for more details.
Parameters
otherElement : elementElement to compare.
Returns
Boolean
-
Checks if this node is read-only (should not be changed).
// For the following HTML: // <b>foo</b><div contenteditable="false"><i>bar</i></div> elB.isReadOnly(); // -> false foo.isReadOnly(); // -> false elDiv.isReadOnly(); // -> true elI.isReadOnly(); // -> trueThis method works in two modes depending on browser support for the
element.isContentEditableproperty and the value of thecheckOnlyAttributesparameter. Theelement.isContentEditablecheck is faster, but it is known to malfunction in hidden or detached nodes. Additionally, when processing some detached DOM tree you may want to imitate that this happens inside an editable container (like it would happen inside the CKEDITOR.editable). To do so, you can temporarily attach this tree to an element with thedata-cke-editableattribute and use thecheckOnlyAttributesmode.Parameters
[ checkOnlyAttributes ] : BooleanIf
true, only attributes will be checked, native methods will not be used. This parameter needs to betrueto check hidden or detached elements. Introduced in 4.5.0.Defaults to
false
Returns
Boolean
isVisible() → BooleanCKEDITOR.dom.element#isVisibleChecks if this element is visible. May not work if the element is child of an element with visibility set to
hidden, but works well on the great majority of cases.Returns
BooleanTrue if the element is visible.
mergeSiblings( [ inlineOnly ] )CKEDITOR.dom.element#mergeSiblingsMerges sibling elements that are identical to this one.
Identical child elements are also merged. For example:
<b><i></i></b><b><i></i></b> => <b><i></i></b>Parameters
[ inlineOnly ] : BooleanAllow only inline elements to be merged.
Defaults to
true
-
moveChildren( target, [ toStart ] )CKEDITOR.dom.element#moveChildrenMoves this element's children to the target element.
Parameters
target : element[ toStart ] : BooleanInsert moved children at the beginning of the target element.
Defaults to
false
inherited
on( eventName, listenerFunction, [ scopeObj ], [ listenerData ], [ priority ] ) → ObjectCKEDITOR.dom.element#onRegisters 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 calledNote: CKEditor's event system has a limitation that one function cannot be used as a listener for the same event more than once. Hence, to reuse it with multiple listeners, it should be wrapped into additional wrapper function:
function listener( evt ) { ... }; someObject.on( 'someEvent', function() { listener(); } ); someObject.on( 'someEvent', function( evt ) { listener( evt ); } );Parameters
eventName : StringThe event name to which listen.
listenerFunction : FunctionThe function listening to the event. A single CKEDITOR.eventInfo object instanced is passed to this function containing all the event data.
[ scopeObj ] : ObjectThe object used to scope the listener call (the
thisobject). If omitted, the current object is used.[ listenerData ] : ObjectData to be sent as the CKEDITOR.eventInfo.listenerData when calling the listener.
[ priority ] : NumberThe listener priority. Lower priority listeners are called first. Listeners with the same priority value are called in registration order.
Defaults to
10
Returns
ObjectAn object containing the
removeListenerfunction, 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.
-
Removes this node from the document DOM.
var element = CKEDITOR.document.getById( 'MyElement' ); element.remove();Parameters
[ preserveChildren ] : BooleanIndicates that the children elements must remain in the document, removing only the outer tags.
Defaults to
false
Returns
nodethis
-
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.
removeAttribute( name )CKEDITOR.dom.element#removeAttributeRemoves an attribute from the element.
var element = CKEDITOR.dom.element.createFromHtml( '<div class="classA"></div>' ); element.removeAttribute( 'class' );Parameters
name : StringThe attribute name.
removeAttributes( [ attributes ] )CKEDITOR.dom.element#removeAttributesRemoves all element's attributes or just given ones.
Parameters
[ attributes ] : ArrayThe array with attributes names.
-
Removes a CSS class name from the elements classes. Other classes remain untouched.
var element = new CKEDITOR.dom.element( 'div' ); element.addClass( 'classA' ); // <div class="classA"> element.addClass( 'classB' ); // <div class="classA classB"> element.removeClass( 'classA' ); // <div class="classB"> element.removeClass( 'classB' ); // <div>Parameters
className : StringThe name of the class to remove.
Returns
elementthis
-
Removes the value in the data slot under the given
key.Parameters
key : String
Returns
ObjectRemoved value or
nullif not found.
-
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 : StringThe event name.
listenerFunction : FunctionThe listener function to unregister.
removeStyle( name )CKEDITOR.dom.element#removeStyleRemoves a style from the element.
var element = CKEDITOR.dom.element.createFromHtml( '<div style="display:none"></div>' ); element.removeStyle( 'display' );Parameters
name : StringThe style name.
renameNode( newTag )CKEDITOR.dom.element#renameNodeChanges the tag name of the current element.
Parameters
newTag : StringThe new tag for the element.
-
scrollIntoParent( parent, [ alignToTop ], [ hscroll ] )CKEDITOR.dom.element#scrollIntoParentMake any page element visible inside one of the ancestors by scrolling the parent.
Parameters
parent : element | windowThe container to scroll into.
[ alignToTop ] : BooleanAlign the element's top side with the container's when
trueis specified; align the bottom with viewport bottom whenfalseis specified. Otherwise scroll on either side with the minimum amount to show the element.[ hscroll ] : BooleanWhether horizontal overflow should be considered.
scrollIntoView( [ alignToTop ] )CKEDITOR.dom.element#scrollIntoViewMake any page element visible inside the browser viewport.
Parameters
[ alignToTop ] : BooleanDefaults to
false
setAttribute( name, value ) → elementCKEDITOR.dom.element#setAttributeSets the value of an element attribute.
var element = CKEDITOR.document.getById( 'myElement' ); element.setAttribute( 'class', 'myClass' ); element.setAttribute( 'title', 'This is an example' );Parameters
name : StringThe name of the attribute.
value : StringThe value to be set to the attribute.
Returns
elementThis element instance.
-
Sets the value of several element attributes.
var element = CKEDITOR.document.getById( 'myElement' ); element.setAttributes( { 'class': 'myClass', title: 'This is an example' } );Parameters
attributesPairs : ObjectAn object containing the names and values of the attributes.
Returns
elementThis element instance.
-
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 guaranteed to be available on this unique DOM node, thus any wish to continue access to 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.Note: This method does not work on text nodes prior to Internet Explorer 9.
var element = new CKEDITOR.dom.element( 'span' ); element.setCustomData( 'hasCustomData', true );Parameters
key : StringA key used to identify the data slot.
value : ObjectThe value to set to the data slot.
Returns
domObjectThis DOM object instance.
setHtml( html ) → StringCKEDITOR.dom.element#setHtmlSets the inner HTML of this element.
var p = new CKEDITOR.dom.element( 'p' ); p.setHtml( '<b>Inner</b> HTML' ); // Result: '<p><b>Inner</b> HTML</p>'Parameters
html : StringThe HTML to be set for this element.
Returns
StringThe inserted HTML.
setOpacity( opacity )CKEDITOR.dom.element#setOpacitySets the opacity of an element.
var element = CKEDITOR.document.getById( 'myElement' ); element.setOpacity( 0.75 );Parameters
opacity : NumberA number within the range
[0.0, 1.0].
setSize( type, size, isBorderBox )CKEDITOR.dom.element#setSizeSets the element size considering the box model.
Parameters
type : 'width' | 'height'The dimension to set.
size : NumberThe length unit in px.
isBorderBox : BooleanApply the size based on the border box model.
setState( state, [ base ], [ useAria ] )CKEDITOR.dom.element#setStateSwitch the
classattribute to reflect one of the triple states of an element in one of CKEDITOR.TRISTATE_ON, CKEDITOR.TRISTATE_OFF or CKEDITOR.TRISTATE_DISABLED.link.setState( CKEDITOR.TRISTATE_ON ); // <a class="cke_on" aria-pressed="true">...</a> link.setState( CKEDITOR.TRISTATE_OFF ); // <a class="cke_off">...</a> link.setState( CKEDITOR.TRISTATE_DISABLED ); // <a class="cke_disabled" aria-disabled="true">...</a> span.setState( CKEDITOR.TRISTATE_ON, 'cke_button' ); // <span class="cke_button_on">...</span>Parameters
state : NumberIndicate the element state. One of CKEDITOR.TRISTATE_ON, CKEDITOR.TRISTATE_OFF, CKEDITOR.TRISTATE_DISABLED.
[ base ] : ObjectThe prefix apply to each of the state class name.
Defaults to
'cke'[ useAria ] : ObjectWhether toggle the ARIA state attributes besides of class name change.
Defaults to
true
-
Sets the value of an element style.
var element = CKEDITOR.document.getById( 'myElement' ); element.setStyle( 'background-color', '#ff0000' ); element.setStyle( 'margin-top', '10px' ); element.setStyle( 'float', 'right' );Parameters
name : StringThe name of the style. The CSS naming notation must be used (e.g.
background-color).value : StringThe value to be set to the style.
Returns
elementThis element instance.
-
Sets the value of several element styles.
var element = CKEDITOR.document.getById( 'myElement' ); element.setStyles( { position: 'absolute', float: 'right' } );Parameters
stylesPairs : ObjectAn object containing the names and values of the styles.
Returns
elementThis element instance.
setText( text ) → StringCKEDITOR.dom.element#setTextSets the element contents as plain text.
var element = new CKEDITOR.dom.element( 'div' ); element.setText( 'A > B & C < D' ); alert( element.innerHTML ); // 'A > B & C < D'Parameters
text : StringThe text to be set.
Returns
StringThe inserted text.
-
Sets the element value. This function is usually used with form field element.
Parameters
value : StringThe element value.
Returns
elementThis element instance.
show()CKEDITOR.dom.element#showShows this element (displays it).
var element = CKEDITOR.document.getById( 'myElement' ); element.show();unselectable()CKEDITOR.dom.element#unselectableMakes the element and its children unselectable.
var element = CKEDITOR.document.getById( 'myElement' ); element.unselectable();
Static methods
-
Removes all markers added using this database. See the setMarker method for more information.
Parameters
database : Object
-
Removes all markers added to this element and removes it from the database if
removeFromDatabasewas passed. See the setMarker method for more information.var database = {}; CKEDITOR.dom.element.setMarker( database, element1, 'foo', 'bar' ); CKEDITOR.dom.element.setMarker( database, element2, 'oof', [ 1, 2, 3 ] ); element1.getCustomData( 'foo' ); // 'bar' element2.getCustomData( 'oof' ); // [ 1, 2, 3 ] CKEDITOR.dom.element.clearMarkers( database, element1, true ); element1.getCustomData( 'foo' ); // null element2.getCustomData( 'oof' ); // [ 1, 2, 3 ]Parameters
database : Object
-
Creates an instance of the CKEDITOR.dom.element class based on the HTML representation of an element.
var element = CKEDITOR.dom.element.createFromHtml( '<strong class="anyclass">My element</strong>' ); alert( element.getName() ); // 'strong'Parameters
html : StringThe element HTML. It should define only one element in the "root" level. The "root" element can have child nodes, but not siblings.
Returns
elementThe element instance.
-
The the CKEDITOR.dom.element representing and element. If the element is a native DOM element, it will be transformed into a valid CKEDITOR.dom.element object.
var element = new CKEDITOR.dom.element( 'span' ); alert( element == CKEDITOR.dom.element.get( element ) ); // true var element = document.getElementById( 'myElement' ); alert( CKEDITOR.dom.element.get( element ).getName() ); // (e.g.) 'p'Parameters
element : String | ObjectElement's id or name or native DOM element.
Returns
elementThe transformed element.
-
Implements the CKEDITOR.event features in an object.
var myObject = { message: 'Example' }; CKEDITOR.event.implementOn( myObject ); myObject.on( 'testEvent', function() { alert( this.message ); } ); myObject.fire( 'testEvent' ); // 'Example'Parameters
targetObject : ObjectThe object into which implement the features.
-
Sets custom data on an element in a way that it is later possible to clear all data set on all elements sharing the same database.
This mechanism is very useful when processing some portion of DOM. All markers can later be removed by calling the clearAllMarkers method, hence markers will not leak to second pass of this algorithm.
var database = {}; CKEDITOR.dom.element.setMarker( database, element1, 'foo', 'bar' ); CKEDITOR.dom.element.setMarker( database, element2, 'oof', [ 1, 2, 3 ] ); element1.getCustomData( 'foo' ); // 'bar' element2.getCustomData( 'oof' ); // [ 1, 2, 3 ] CKEDITOR.dom.element.clearAllMarkers( database ); element1.getCustomData( 'foo' ); // nullParameters
database : Objectelement : elementname : Stringvalue : Object
Returns
elementThe element.