dom_set-attributes.js

/**
 * @module setAttributes
 * @description Set multiple element attributes at once on a passed DOM element.
 *
 * @since 1.0.0
 *
 * @param {HTMLElement} el    The element to apply the attributes to.
 * @param {object}      attrs The attributes as object with key being attribute name, value being value.
 *
 * @return {void}
 *
 * @example
 * import { setAttributes } from "@gravityforms/utils";
 *
 * function Example() {
 *   const node = getNodes( 'example' )[ 0 ];
 *   const attributes = {
 *       'aria-hidden': 'true',
 *       'id': 'example',
 *   };
 *   setAttributes( node, attributes );
 * }
 *
 */
export default function setAttributes( el, attrs ) {
	Object.keys( attrs ).forEach( ( key ) => el.setAttribute( key, attrs[ key ] ) );
}