Dom

dom.Dom

Module for working with DOM

detach

detach(node): void

Remove all content from element

Parameters

Name Type
node Nullable<Node>

Returns

void

Defined in

src/core/dom/dom.ts#53


wrapInline

wrapInline(current, tag, editor): HTMLElement

Wrap all inline siblings

Parameters

Name Type
current Node
tag Node | HTMLTagNames
editor IJodit

Returns

HTMLElement

Defined in

src/core/dom/dom.ts#62


wrap

wrap<K>(current, tag, create): HTMLElementTagNameMap[K]

Wrap node inside another node

Type parameters

Name Type
K extends HTMLTagNames

Parameters

Name Type
current Node | Range
tag HTMLElement
create ICreate

Returns

HTMLElementTagNameMap[K]

Defined in

src/core/dom/dom.ts#119

wrap<K>(current, tag, create): HTMLElementTagNameMap[K]

Wrap node inside another node

Type parameters

Name Type
K extends HTMLTagNames

Parameters

Name Type
current Node | Range
tag K
create ICreate

Returns

HTMLElementTagNameMap[K]

Defined in

src/core/dom/dom.ts#125


unwrap

unwrap(node): void

Remove parent of node and insert this node instead that parent

Parameters

Name Type
node Node

Returns

void

Defined in

src/core/dom/dom.ts#160


between

between(start, end, callback): void

Call functions for all nodes between start and end

Parameters

Name Type
start Node
end Node
callback (node: Node) => boolean | void

Returns

void

Defined in

src/core/dom/dom.ts#175


replace

replace<T>(elm, newTagName, create, withAttributes?, notMoveContent?): T

Replace one tag to another transfer content

Type parameters

Name Type
T extends HTMLElement

Parameters

Name Type Description
elm Node The element that needs to be replaced by new
newTagName HTMLTagNames tag name for which will change elm
create ICreate -
withAttributes? boolean If true move tag's attributes
notMoveContent? boolean false - Move content from elm to newTagName

Returns

T

Example

Jodit.modules.Dom.replace(parent.editor.getElementsByTagName('span')[0], 'p');
// Replace the first <span> element to the < p >
Defined in

src/core/dom/dom.ts#214

replace<T>(elm, newTagName, create, withAttributes?, notMoveContent?): T

Type parameters

Name Type
T extends Node

Parameters

Name Type
elm Node
newTagName string | T
create ICreate
withAttributes? boolean
notMoveContent? boolean

Returns

T

Defined in

src/core/dom/dom.ts#221


isEmptyTextNode

isEmptyTextNode(node): boolean

Checks whether the Node text and blank (in this case it may contain invisible auxiliary characters ,
it is also empty )

Parameters

Name Type Description
node Nullable<Node> The element of wood to be checked

Returns

boolean

Defined in

src/core/dom/dom.ts#268


isEmptyContent

isEmptyContent(node): boolean

Parameters

Name Type
node Node

Returns

boolean

Defined in

src/core/dom/dom.ts#278


isContentEditable

isContentEditable(node, root): boolean

The node is editable

Parameters

Name Type
node Nullable<Node>
root HTMLElement

Returns

boolean

Defined in

src/core/dom/dom.ts#287


isEmpty

isEmpty(node, condNoEmptyElement): boolean

Check if element is empty

Parameters

Name Type
node Node
condNoEmptyElement (node: Element) => boolean

Returns

boolean

Defined in

src/core/dom/dom.ts#303

isEmpty(node, noEmptyTags?): boolean

Parameters

Name Type
node Node
noEmptyTags? Set<string>

Returns

boolean

Defined in

src/core/dom/dom.ts#307


isNode

isNode(object): object is Node

Returns true if it is a DOM node

Parameters

Name Type
object unknown

Returns

object is Node

Defined in

src/core/dom/dom.ts#350


isCell

isCell(elm): elm is HTMLTableCellElement

Check if element is table cell

Parameters

Name Type
elm unknown

Returns

elm is HTMLTableCellElement

Defined in

src/core/dom/dom.ts#364


isList

isList(elm): elm is HTMLOListElement

Check if element is a list element UL or OL

Parameters

Name Type
elm Nullable<Node>

Returns

elm is HTMLOListElement

Defined in

src/core/dom/dom.ts#373


isLeaf

isLeaf(elm): elm is HTMLLIElement

Check if element is a part of list element LI

Parameters

Name Type
elm Nullable<Node>

Returns

elm is HTMLLIElement

Defined in

src/core/dom/dom.ts#380


isImage

isImage(elm): elm is HTMLImageElement

Check is element is Image element

Parameters

Name Type
elm unknown

Returns

elm is HTMLImageElement

Defined in

src/core/dom/dom.ts#387


isBlock

isBlock(node): node is HTMLDivElement

Check the node is a block element

Parameters

Name Type Description
node unknown Object to check

Returns

node is HTMLDivElement

Defined in

src/core/dom/dom.ts#397


isText

isText(node): node is Text

Check if element is text node

Parameters

Name Type
node null | false | Node

Returns

node is Text

Defined in

src/core/dom/dom.ts#409


isComment

isComment(node): node is Comment

Check if element is comment node

Parameters

Name Type
node Node

Returns

node is Comment

Defined in

src/core/dom/dom.ts#416


isElement

isElement(node): node is Element

Check if element is element node

Parameters

Name Type
node unknown

Returns

node is Element

Defined in

src/core/dom/dom.ts#423


isFragment

isFragment(node): node is DocumentFragment

Check if element is document fragment

Parameters

Name Type
node unknown

Returns

node is DocumentFragment

Defined in

src/core/dom/dom.ts#436


isHTMLElement

isHTMLElement(node): node is HTMLElement

Check if element is HTMLElement node

Parameters

Name Type
node unknown

Returns

node is HTMLElement

Defined in

src/core/dom/dom.ts#449


isInlineBlock

isInlineBlock(node): node is HTMLElement

Check element is inline block

Parameters

Name Type
node null | false | Node

Returns

node is HTMLElement

Defined in

src/core/dom/dom.ts#462


canSplitBlock

canSplitBlock(node): boolean

It's block and it can be split

Parameters

Name Type
node unknown

Returns

boolean

Defined in

src/core/dom/dom.ts#475


last

last(root, condition): Nullable<Node>

Get last matched node inside root

Parameters

Name Type
root Nullable<Node>
condition NodeCondition

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#489


prev

prev<T>(node, condition, root, withChild?): Nullable<T>

Find previous node

Type parameters

Name Type
T extends Node = Node

Parameters

Name Type Default value
node Node undefined
condition NodeCondition undefined
root HTMLElement undefined
withChild boolean true

Returns

Nullable<T>

Defined in

src/core/dom/dom.ts#531


next

next<T>(node, condition, root, withChild?): Nullable<T>

Find next node what condition(next) === true

Type parameters

Name Type
T extends Node = Node

Parameters

Name Type Default value
node Node undefined
condition NodeCondition undefined
root HTMLElement undefined
withChild boolean true

Returns

Nullable<T>

Defined in

src/core/dom/dom.ts#543


prevWithClass

prevWithClass(node, className): Nullable<HTMLElement>

Parameters

Name Type
node HTMLElement
className string

Returns

Nullable<HTMLElement>

Defined in

src/core/dom/dom.ts#552


nextWithClass

nextWithClass(node, className): Nullable<HTMLElement>

Parameters

Name Type
node HTMLElement
className string

Returns

Nullable<HTMLElement>

Defined in

src/core/dom/dom.ts#567


find

find<T>(node, condition, root, leftToRight?, withChild?): Nullable<T>

Find next/prev node what condition(next) === true

Type parameters

Name Type
T extends Node = Node

Parameters

Name Type Default value
node Node undefined
condition NodeCondition undefined
root HTMLElement undefined
leftToRight boolean true
withChild boolean true

Returns

Nullable<T>

Defined in

src/core/dom/dom.ts#581


nextGen

nextGen(start, root, leftToRight?, withChild?): Generator<Node, any, unknown>

Find next/prev node what condition(next) === true

Parameters

Name Type Default value
start Node undefined
root HTMLElement undefined
leftToRight boolean true
withChild boolean true

Returns

Generator<Node, any, unknown>

Defined in

src/core/dom/dom.ts#606


each

each(elm, callback, leftToRight?): boolean

It goes through all the internal elements of the node, causing a callback function

Parameters

Name Type Default value Description
elm Node undefined the element whose children and descendants you want to iterate over
callback (node: Node) => boolean | void undefined It called for each item found
leftToRight boolean true -

Returns

boolean

Example

Jodit.modules.Dom.each(editor.s.current(), function (node) {
 if (node.nodeType === Node.TEXT_NODE) {
     node.nodeValue = node.nodeValue.replace(Jodit.INVISIBLE_SPACE_REG_EX, '') // remove all of the text element codes invisible character
 }
});
Defined in

src/core/dom/dom.ts#648


eachGen

eachGen(root, leftToRight?): Generator<Node, any, unknown>

Parameters

Name Type Default value
root Node undefined
leftToRight boolean true

Returns

Generator<Node, any, unknown>

Defined in

src/core/dom/dom.ts#668


findWithCurrent

findWithCurrent(node, condition, root, sibling?, child?): Nullable<Node>

Find next/prev node what condition(next) === true

Parameters

Name Type Default value
node Node undefined
condition NodeCondition undefined
root Node | HTMLElement undefined
sibling "nextSibling" | "previousSibling" 'nextSibling'
child "firstChild" | "lastChild" 'firstChild'

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#701


findSibling

findSibling(node, left?, cond?): Nullable<Node>

Get not empty sibling

Parameters

Name Type Default value
node Node undefined
left boolean true
cond (n: Node) => boolean undefined

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#744


findNotEmptySibling

findNotEmptySibling(node, left): Nullable<Node>

Returns the nearest non-empty sibling

Parameters

Name Type
node Node
left boolean

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#762


findNotEmptyNeighbor

findNotEmptyNeighbor(node, left, root): Nullable<Node>

Returns the nearest non-empty neighbor

Parameters

Name Type
node Node
left boolean
root HTMLElement

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#776


sibling

sibling(node, left?): Nullable<Node>

Parameters

Name Type
node Node
left? boolean

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#794


up

up<T>(node, condition, root?, checkRoot?): Nullable<T>

It goes through all the elements in ascending order, and checks to see if they meet the predetermined condition

Type parameters

Name Type
T extends HTMLElement

Parameters

Name Type Default value
node Nullable<Node> undefined
condition NodeCondition undefined
root? Node undefined
checkRoot boolean false

Returns

Nullable<T>

Defined in

src/core/dom/dom.ts#801


closest

closest<T, K>(node, tags, root): Nullable<HTMLElementTagNameMap[K]>

Find parent by tag name

Type parameters

Name Type
T extends HTMLElement
K extends HTMLTagNames

Parameters

Name Type
node Nullable<Node>
tags K
root HTMLElement

Returns

Nullable<HTMLElementTagNameMap[K]>

Defined in

src/core/dom/dom.ts#835

closest<T, K>(node, tags, root): Nullable<HTMLElementTagNameMap[K]>

Type parameters

Name Type
T extends HTMLElement
K extends keyof HTMLElementTagNameMap

Parameters

Name Type
node Nullable<Node>
tags Set<K>
root HTMLElement

Returns

Nullable<HTMLElementTagNameMap[K]>

Defined in

src/core/dom/dom.ts#841

closest<T, K>(node, tags, root): Nullable<HTMLElementTagNameMap[K]>

Type parameters

Name Type
T extends HTMLElement
K extends keyof HTMLElementTagNameMap

Parameters

Name Type
node Nullable<Node>
tags K[]
root HTMLElement

Returns

Nullable<HTMLElementTagNameMap[K]>

Defined in

src/core/dom/dom.ts#850

closest<T>(node, condition, root): Nullable<T>

Type parameters

Name Type
T extends HTMLElement

Parameters

Name Type
node Nullable<Node>
condition NodeCondition
root HTMLElement

Returns

Nullable<T>

Defined in

src/core/dom/dom.ts#859


furthest

furthest<T>(node, condition, root): Nullable<T>

Furthest parent node matching condition

Type parameters

Name Type
T extends HTMLElement

Parameters

Name Type
node Nullable<Node>
condition NodeCondition
root HTMLElement

Returns

Nullable<T>

Defined in

src/core/dom/dom.ts#897


appendChildFirst

appendChildFirst(root, newElement): void

Append new element in the start of root

Parameters

Name Type
root HTMLElement
newElement HTMLElement | DocumentFragment

Returns

void

Defined in

src/core/dom/dom.ts#919


after

after(elm, newElement): void

Insert newElement after element

Parameters

Name Type
elm Node
newElement Node | DocumentFragment

Returns

void

Defined in

src/core/dom/dom.ts#937


before

before(elm, newElement): void

Insert newElement before element

Parameters

Name Type
elm Node
newElement Node | DocumentFragment

Returns

void

Defined in

src/core/dom/dom.ts#954


prepend

prepend(root, newElement): void

Insert newElement as first child inside element

Parameters

Name Type
root Node
newElement Node | DocumentFragment

Returns

void

Defined in

src/core/dom/dom.ts#967


append

append(root, newElements): void

Insert newElement as last child inside element

Parameters

Name Type
root Node
newElements (Node | DocumentFragment)[]

Returns

void

Defined in

src/core/dom/dom.ts#974

append(root, newElement): void

Parameters

Name Type
root Node
newElement Node | DocumentFragment

Returns

void

Defined in

src/core/dom/dom.ts#979


moveContent

moveContent(from, to, inStart?, filter?): void

Move all content to another element

Parameters

Name Type Default value
from Node undefined
to Node undefined
inStart boolean false
filter (node: Node) => boolean undefined

Returns

void

Defined in

src/core/dom/dom.ts#997


isOrContains

isOrContains(root, child, onlyContains?): boolean

Check root contains child or equal child

Parameters

Name Type Default value
root Node undefined
child Node undefined
onlyContains boolean false

Returns

boolean

Defined in

src/core/dom/dom.ts#1030


safeRemove

safeRemove(...nodes): void

Safe remove element from DOM

Parameters

Name Type
...nodes unknown[]

Returns

void

Defined in

src/core/dom/dom.ts#1047


safeInsertNode

safeInsertNode(range, node): void

Parameters

Name Type
range Range
node Node

Returns

void

Defined in

src/core/dom/dom.ts#1056


hide

hide(node): void

Hide element

Parameters

Name Type
node Nullable<HTMLElement>

Returns

void

Defined in

src/core/dom/dom.ts#1084


show

show(node): void

Show element

Parameters

Name Type
node Nullable<HTMLElement>

Returns

void

Defined in

src/core/dom/dom.ts#1096


isTag

isTag<K>(node, tagName): node is HTMLElementTagNameMap[K]

Check if element is some tag

Type parameters

Name Type
K extends HTMLTagNames

Parameters

Name Type
node undefined | null | false | EventTarget | Node
tagName K

Returns

node is HTMLElementTagNameMap[K]

Defined in

src/core/dom/dom.ts#1111

isTag<K>(node, tagNames): node is HTMLElementTagNameMap[K]

Type parameters

Name Type
K extends HTMLTagNames

Parameters

Name Type
node undefined | null | false | EventTarget | Node
tagNames Set<K>

Returns

node is HTMLElementTagNameMap[K]

Defined in

src/core/dom/dom.ts#1116


markTemporary

markTemporary<K>(element, attributes?): K

Marks an item as temporary

Type parameters

Name Type
K extends HTMLElement

Parameters

Name Type
element K
attributes? IDictionary

Returns

K

Defined in

src/core/dom/dom.ts#1152


isTemporary

isTemporary(element): boolean

Check if element is temporary

Parameters

Name Type
element unknown

Returns

boolean

Defined in

src/core/dom/dom.ts#1164


replaceTemporaryFromString

replaceTemporaryFromString(value): string

Replace temporary elements from string

Parameters

Name Type
value string

Returns

string

Defined in

src/core/dom/dom.ts#1175


temporaryList

temporaryList(root): HTMLElement[]

Get temporary list

Parameters

Name Type
root HTMLElement

Returns

HTMLElement[]

Defined in

jodit/src/core/dom/dom.ts:1185