Created
July 30, 2014 19:29
-
-
Save jonasporto/0104d736019a5193c36b to your computer and use it in GitHub Desktop.
get elements by atributes javascript
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)) | |
| { | |
| // Element exists with attribute. Add to array. | |
| matchingElements.push(allElements[i]); | |
| } | |
| } | |
| return matchingElements; | |
| } | |
| //by http://stackoverflow.com/questions/9496427/can-i-get-elements-by-attribute-selector-when-queryselectorall-is-not-available |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment