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#62


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#71


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#128

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#134


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#169


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#184


replace

replace<T>(elm, newTagName): 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

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#223

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

Type parameters

Name Type
T extends HTMLElement

Parameters

Name Type
elm Node
newTagName HTMLTagNames
create ICreate
withAttributes? boolean
notMoveContent? boolean

Returns

T

Defined in

src/core/dom/dom.ts#227

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#234


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#286


isEmptyContent

isEmptyContent(node): boolean

Parameters

Name Type
node Node

Returns

boolean

Defined in

src/core/dom/dom.ts#296


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#305


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#321

isEmpty(node, noEmptyTags?): boolean

Parameters

Name Type
node Node
noEmptyTags? Set<string>

Returns

boolean

Defined in

src/core/dom/dom.ts#325


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#368


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#382


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#391


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#398


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#405


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#415


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#427


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#434


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#441


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#454


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#467


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#480


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#493


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#507


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#549


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#561


prevWithClass

prevWithClass(node, className): Nullable<HTMLElement>

Parameters

Name Type
node HTMLElement
className string

Returns

Nullable<HTMLElement>

Defined in

src/core/dom/dom.ts#570


nextWithClass

nextWithClass(node, className): Nullable<HTMLElement>

Parameters

Name Type
node HTMLElement
className string

Returns

Nullable<HTMLElement>

Defined in

src/core/dom/dom.ts#585


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#599


nextGen

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

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, any>

Defined in

src/core/dom/dom.ts#624


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#666


eachGen

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

Parameters

Name Type Default value
root Node undefined
leftToRight boolean true

Returns

Generator<Node, any, any>

Defined in

src/core/dom/dom.ts#686


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#719


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#762


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#780


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#794


sibling

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

Parameters

Name Type
node Node
left? boolean

Returns

Nullable<Node>

Defined in

src/core/dom/dom.ts#812


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#819


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#853

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#859

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#868

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#877


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#915


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#937


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#955


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#972


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#985


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#992

append(root, newElement): void

Parameters

Name Type
root Node
newElement Node | DocumentFragment

Returns

void

Defined in

src/core/dom/dom.ts#997


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#1015


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#1048


safeRemove

safeRemove(...nodes): void

Safe remove element from DOM

Parameters

Name Type
...nodes unknown[]

Returns

void

Defined in

src/core/dom/dom.ts#1065


safeInsertNode

safeInsertNode(range, node): void

Parameters

Name Type
range Range
node Node

Returns

void

Defined in

src/core/dom/dom.ts#1074


hide

hide(node): void

Hide element

Parameters

Name Type
node Nullable<HTMLElement>

Returns

void

Defined in

src/core/dom/dom.ts#1102


show

show(node): void

Show element

Parameters

Name Type
node Nullable<HTMLElement>

Returns

void

Defined in

src/core/dom/dom.ts#1114


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#1129

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#1134


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#1170


isTemporary

isTemporary(element): boolean

Check if element is temporary

Parameters

Name Type
element unknown

Returns

boolean

Defined in

src/core/dom/dom.ts#1182


replaceTemporaryFromString

replaceTemporaryFromString(value): string

Replace temporary elements from string

Parameters

Name Type
value string

Returns

string

Defined in

src/core/dom/dom.ts#1193


temporaryList

temporaryList(root): HTMLElement[]

Get temporary list

Parameters

Name Type
root HTMLElement

Returns

HTMLElement[]

Defined in

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