Created
April 4, 2016 08:40
-
-
Save et4891/3a45f5e6d054c48cbad37446102e758d to your computer and use it in GitHub Desktop.
getAllElementsWithAttribute
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
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