Last active
October 30, 2015 13:48
-
-
Save DamianMullins/9f84cd13d7ed17463c74 to your computer and use it in GitHub Desktop.
Returns an array of elements with a matching data attribute name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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