Skip to content

Instantly share code, notes, and snippets.

@et4891
Created April 4, 2016 08:40
Show Gist options
  • Save et4891/3a45f5e6d054c48cbad37446102e758d to your computer and use it in GitHub Desktop.
Save et4891/3a45f5e6d054c48cbad37446102e758d to your computer and use it in GitHub Desktop.
getAllElementsWithAttribute
function getAllElementsWithAttribute(attribute)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
return matchingElements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment