CodyHouse Framework + Components are featured on Product Hunt! Join the discussion →

All Projects

Utilities (JS)

The util.js file contains a set of JavaScript utility functions that are used across multiple components

Browser support: IE9+ and modern browsers.


🔍 On this page:

  1. Class Manipulation
  2. DOM Methods
  3. Focus
  4. Misc

Class Manipulation #

These functions can be used to add/remove classes from DOM elements.

Function Description
Util.addClass(element, 'className') add a class (or list of classes) to an element
Util.removeClass(element, 'className') remove a class (or list of classes) to an element
Util.hasClass(element, 'className') check if element has a specified class
Util.toggleClass(element, 'className', bool) add or remove a class (or list of classes) to an element (based on the value of bool)

DOM Methods #

These functions can be used to search the DOM or get info about a specific node.

Function Description
Util.getChildrenByClassName(parent, 'className') return children of an element with a specific class
Util.is(element, selector) check if the element matches a specific selector
Util.getIndexInArray(array, element) return the index of an element in a node array

Focus #

This function can be used to move the focus to a new DOM element (works also for elements that cannot receive the focus).

Function Description
Util.moveFocus(element) move focus to a new DOM element

Misc #

Function Description
Util.cssSupports('property', 'value') check if a CSS property and/or value are supported
Util.extend(default, options) merge a set of user options into a list of defaults
Util.osHasReducedMotion() return true if Reduced Motion is enabled

Project duplicated.