feat: added a prepend function
This commit is contained in:
parent
8d3b629185
commit
f106776bee
1 changed files with 18 additions and 0 deletions
18
src/HTML.ts
18
src/HTML.ts
|
|
@ -196,6 +196,24 @@ export default class HTML {
|
|||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend an element. Typically used as a `.prepend(new HTML(...))` call.
|
||||
* @param elem The element to prepend.
|
||||
* @returns HTML
|
||||
*/
|
||||
prepend (elem: string | HTMLElement | HTML): HTML {
|
||||
if (elem instanceof HTMLElement) {
|
||||
this.elm.prepend(elem)
|
||||
} else if (elem instanceof HTML) {
|
||||
this.elm.prepend(elem.elm)
|
||||
} else if (typeof elem === 'string') {
|
||||
const newElem = document.createElement(elem)
|
||||
this.elm.prepend(newElem)
|
||||
return new HTML(newElem.tagName)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Append multiple elements. Typically used as a `.appendMany(new HTML(...), new HTML(...)` call.
|
||||
* @param elements The elements to append.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue