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
wrapInline
wrapInline(current
, tag
, editor
): HTMLElement
Wrap all inline siblings
Parameters
Name | Type |
---|---|
current |
Node |
tag |
Node | HTMLTagNames |
editor |
IJodit |
Returns
Defined in
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
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
unwrap
unwrap(node
): void
Remove parent of node and insert this node instead that parent
Parameters
Name | Type |
---|---|
node |
Node |
Returns
void
Defined in
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
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
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
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
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
isEmptyContent
isEmptyContent(node
): boolean
Parameters
Name | Type |
---|---|
node |
Node |
Returns
boolean
Defined in
isContentEditable
isContentEditable(node
, root
): boolean
The node is editable
Parameters
Name | Type |
---|---|
node |
Nullable <Node > |
root |
HTMLElement |
Returns
boolean
Defined in
isEmpty
isEmpty(node
, condNoEmptyElement
): boolean
Check if element is empty
Parameters
Name | Type |
---|---|
node |
Node |
condNoEmptyElement |
(node : Element ) => boolean |
Returns
boolean
Defined in
isEmpty(node
, noEmptyTags?
): boolean
Parameters
Name | Type |
---|---|
node |
Node |
noEmptyTags? |
Set <string > |
Returns
boolean
Defined in
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
isCell
isCell(elm
): elm is HTMLTableCellElement
Check if element is table cell
Parameters
Name | Type |
---|---|
elm |
unknown |
Returns
elm is HTMLTableCellElement
Defined in
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
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
isImage
isImage(elm
): elm is HTMLImageElement
Check is element is Image element
Parameters
Name | Type |
---|---|
elm |
unknown |
Returns
elm is HTMLImageElement
Defined in
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
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
isComment
isComment(node
): node is Comment
Check if element is comment node
Parameters
Name | Type |
---|---|
node |
Node |
Returns
node is Comment
Defined in
isElement
isElement(node
): node is Element
Check if element is element node
Parameters
Name | Type |
---|---|
node |
unknown |
Returns
node is Element
Defined in
isFragment
isFragment(node
): node is DocumentFragment
Check if element is document fragment
Parameters
Name | Type |
---|---|
node |
unknown |
Returns
node is DocumentFragment
Defined in
isHTMLElement
isHTMLElement(node
): node is HTMLElement
Check if element is HTMLElement node
Parameters
Name | Type |
---|---|
node |
unknown |
Returns
node is HTMLElement
Defined in
isInlineBlock
isInlineBlock(node
): node is HTMLElement
Check element is inline block
Parameters
Name | Type |
---|---|
node |
null | false | Node |
Returns
node is HTMLElement
Defined in
canSplitBlock
canSplitBlock(node
): boolean
It's block and it can be split
Parameters
Name | Type |
---|---|
node |
unknown |
Returns
boolean
Defined in
last
last(root
, condition
): Nullable
<Node
>
Get last matched node inside root
Parameters
Name | Type |
---|---|
root |
Nullable <Node > |
condition |
NodeCondition |
Returns
Defined in
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
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
prevWithClass
prevWithClass(node
, className
): Nullable
<HTMLElement
>
Parameters
Name | Type |
---|---|
node |
HTMLElement |
className |
string |
Returns
Defined in
nextWithClass
nextWithClass(node
, className
): Nullable
<HTMLElement
>
Parameters
Name | Type |
---|---|
node |
HTMLElement |
className |
string |
Returns
Defined in
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
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
Defined in
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
eachGen
eachGen(root
, leftToRight?
): Generator
<Node
, any
, any
>
Parameters
Name | Type | Default value |
---|---|---|
root |
Node |
undefined |
leftToRight |
boolean |
true |
Returns
Defined in
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
Defined in
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
Defined in
findNotEmptySibling
findNotEmptySibling(node
, left
): Nullable
<Node
>
Returns the nearest non-empty sibling
Parameters
Name | Type |
---|---|
node |
Node |
left |
boolean |
Returns
Defined in
findNotEmptyNeighbor
findNotEmptyNeighbor(node
, left
, root
): Nullable
<Node
>
Returns the nearest non-empty neighbor
Parameters
Name | Type |
---|---|
node |
Node |
left |
boolean |
root |
HTMLElement |
Returns
Defined in
sibling
sibling(node
, left?
): Nullable
<Node
>
Parameters
Name | Type |
---|---|
node |
Node |
left? |
boolean |
Returns
Defined in
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
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
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
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
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
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
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
after
after(elm
, newElement
): void
Insert newElement after element
Parameters
Name | Type |
---|---|
elm |
Node |
newElement |
Node | DocumentFragment |
Returns
void
Defined in
before
before(elm
, newElement
): void
Insert newElement before element
Parameters
Name | Type |
---|---|
elm |
Node |
newElement |
Node | DocumentFragment |
Returns
void
Defined in
prepend
prepend(root
, newElement
): void
Insert newElement as first child inside element
Parameters
Name | Type |
---|---|
root |
Node |
newElement |
Node | DocumentFragment |
Returns
void
Defined in
append
append(root
, newElements
): void
Insert newElement as last child inside element
Parameters
Name | Type |
---|---|
root |
Node |
newElements |
(Node | DocumentFragment )[] |
Returns
void
Defined in
append(root
, newElement
): void
Parameters
Name | Type |
---|---|
root |
Node |
newElement |
Node | DocumentFragment |
Returns
void
Defined in
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
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
safeRemove
safeRemove(...nodes
): void
Safe remove element from DOM
Parameters
Name | Type |
---|---|
...nodes |
unknown [] |
Returns
void
Defined in
safeInsertNode
safeInsertNode(range
, node
): void
Parameters
Name | Type |
---|---|
range |
Range |
node |
Node |
Returns
void
Defined in
hide
hide(node
): void
Hide element
Parameters
Name | Type |
---|---|
node |
Nullable <HTMLElement > |
Returns
void
Defined in
show
show(node
): void
Show element
Parameters
Name | Type |
---|---|
node |
Nullable <HTMLElement > |
Returns
void
Defined in
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
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
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
isTemporary
isTemporary(element
): boolean
Check if element is temporary
Parameters
Name | Type |
---|---|
element |
unknown |
Returns
boolean
Defined in
replaceTemporaryFromString
replaceTemporaryFromString(value
): string
Replace temporary elements from string
Parameters
Name | Type |
---|---|
value |
string |
Returns
string
Defined in
temporaryList
temporaryList(root
): HTMLElement
[]
Get temporary list
Parameters
Name | Type |
---|---|
root |
HTMLElement |
Returns
Defined in
jodit/src/core/dom/dom.ts:1203