Skip to 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 updated
durationnumbernoneDuration in ms to animate for
optionsobjectnoneOptions to customize the animation
options.timingfunctionnoneOptional function calculating progress based on current time fraction. Linear by default.

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: HTMLElement - The created HTML element


onRemoved

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

ParameterTypeDescription
nodeHTMLElementNode to be observed
callbackfunctionFunction to run when removed

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 used for the style element

Returns: void