Skip to main content

DOM

DOM is a simple utility class for dom manipulation. An instance is available on BdApi.

Properties

screenHeight

Current height of the user's screen.

Type: number


screenWidth

Current width of the user's screen.

Type: number


Methods

addStyle

Adds a <style> to the document with the given ID.

ParameterTypeDescription
idstringID to use for style element
cssstringCSS to apply to the document

Returns: void


animate

Utility to help smoothly animate using JavaScript

ParameterTypeOptionalDefaultDescription
updatefunctionnonerender function indicating the style should be updates
durationnumbernoneduration in ms to animate for
optionsobjectnoneoption to customize the animation

Returns: void


createElement

Utility function to make creating DOM elements easier. Acts similarly to React.createElement

ParameterTypeOptionalDefaultDescription
tagstringnoneHTML tag name to create
optionsobjectnoneoptions object to customize the element
options.classNamestringnoneclass name to add to the element
options.idstringnoneid to set for the element
options.targetHTMLElementnonetarget element to automatically append to
childHTMLElementnonechild node to add

Returns: void


onRemoved

Adds a listener for when the node is removed from the document body.

ParameterTypeDescription
nodeHTMLElementNode to be observed
callbackfunctionFunction to run when fired

Returns: void


parseHTML

Parses a string of HTML and returns the results. If the second parameter is true, the parsed HTML will be returned as a document fragment {@see https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment}. This is extremely useful if you have a list of elements at the top level, they can then be appended all at once to another node. If the second parameter is false, then the return value will be the list of parsed nodes and there were multiple top level nodes, otherwise the single node is returned.

ParameterTypeOptionalDefaultDescription
htmlstringnoneHTML to be parsed
fragmentbooleanfalseWhether or not the return should be the raw DocumentFragment

Returns: DocumentFragment - - The result of HTML parsing


removeStyle

Removes a <style> from the document corresponding to the given ID.

ParameterTypeDescription
idstringID uses for the style element

Returns: void