AppHelpers class provides a collection of utility methods for common DOM manipulation tasks, event handling, and element management in Theme Raed.
Class overview
AppHelpers is a helper class that simplifies working with DOM elements through a chainable API. It provides methods for querying elements, managing classes, handling events, and controlling element visibility.
Methods
toggleClassIf
Toggles between two sets of CSS classes on elements based on a callback condition.CSS selector for target elements
First set of CSS classes to toggle
Second set of CSS classes to toggle
Function that determines which classes to apply
element
Retrieves a DOM element by selector or returns the element if already an HTMLElement.CSS selector string or HTMLElement object
The matched element(s) or null if not found
For certain selectors like
.total-price, .before-price, and .product-weight, this method returns a NodeList instead of a single element.watchElement
Stores a reference to an element on the helper instance for later use.Property name to store the element reference
CSS selector for the element to watch
watchElements
Stores references to multiple elements at once.Object mapping property names to CSS selectors
on
Attaches event listeners to elements with optional configuration.Event type (e.g., ‘click’, ‘keyup’, ‘change’)
CSS selector or HTMLElement
Event handler function
Event listener options (optional)
onClick
Convenience method for attaching click event listeners.CSS selector or HTMLElement
Click handler function
onKeyUp
Convenience method for attaching keyup event listeners.CSS selector or HTMLElement
Keyup handler function
all
Iterates over all elements matching a selector and executes a callback.CSS selector for elements to iterate
Function to execute for each element
hideElement
Hides an element by setting its display style to ‘none’.CSS selector or HTMLElement to hide
showElement
Shows a hidden element by setting its display style.CSS selector or HTMLElement to show
CSS display value (e.g., ‘block’, ‘flex’, ‘grid’)
removeClass
Removes one or more CSS classes from an element.CSS selector or HTMLElement
Class name(s) to remove
You can pass multiple class names as separate arguments to remove them all at once.
addClass
Adds one or more CSS classes to an element.CSS selector or HTMLElement
Class name(s) to add
You can pass multiple class names as separate arguments to add them all at once.
Method chaining
Most methods return theAppHelpers instance, allowing for method chaining: