Created
May 17, 2016 22:33
-
-
Save djalmajr/b32b92f6616d942bf0311448d1965513 to your computer and use it in GitHub Desktop.
getElementsByAttr
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 getElementsByAttr(attribute, value, parent) { | |
var matchingElements = [], | |
allElements = (parent || document).getElementsByTagName("*"); | |
for (var i = 0, n = allElements.length; i < n; i++) { | |
if (allElements[i].getAttribute(attribute) === value) { | |
// 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