UNPKG

@gravityforms/utils

Version:
34 lines (33 loc) 991 B
/** * @module removeClassThatContains * @description Remove all classes from an HTMLElement that contain a particular string. * * @since 1.0.0 * * @param {HTMLElement} el The element to remove classes from. * @param {string} string The string to remove any classes that contain it from the passed el. * * @return {void} * * @example * import { getNodes, openNewTab } from "@gravityforms/utils"; * * function Example() { * const node = getNodes( 'example' )[ 0 ]; * node.classList.add( 'gform-block' ); * node.classList.add( 'gform-block--red' ); * node.classList.add( 'block' ); * node.classList.add( 'width-auto' ); * * removeClassThatContains( node, 'gform' ); * console.log( node.classList ); * } * */ export default function removeClassThatContains( el, string = '' ) { for ( let i = 0; i < el.classList.length; i++ ) { if ( el.classList.item( i ).indexOf( string ) !== -1 ) { el.classList.remove( el.classList.item( i ) ); } } }