Skip to content

Instantly share code, notes, and snippets.

@DamianMullins
Last active October 30, 2015 13:48
Show Gist options
  • Save DamianMullins/9f84cd13d7ed17463c74 to your computer and use it in GitHub Desktop.
Save DamianMullins/9f84cd13d7ed17463c74 to your computer and use it in GitHub Desktop.
Returns an array of elements with a matching data attribute name.
/**
* Returns an array of elements with a matching data attribute name.
* @example
* let value = getElementsByDataAttribute('component-name');
*/
export default function getElementsByDataAttribute(name) {
var elements = document.querySelectorAll(`[data-${name}]`);
return Array.prototype.slice.call(elements);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment