You can zoom in something like this by repeating the attributes for each element in the container and seeing if the attribute name matches the regular expression for what you are looking for:
For example, in this jsFiddle, I am looking for li elements with data-media-tv and data-media-dvd properties .
You can set up a regular expression to return only what you want to see. Do you want to see only elements that have media-data * (for example, in your question)? Here you go .
Keep in mind that this is not scalable. . Since we iterate through each element on the page and check each individual attribute (but return earlier if we find), this can and will probably be slow for large pages.
Limit this ONLY to the container you want to search for, or only those elements that you want to iterate over! If you run this against document.body , it will iterate over each element on the page, I will not be responsible if your house burns out as a result. :)
Here it is functional:
function attrMatch(elements, regexp) { // Iterate through all passed-in elements, return matches var matches = elements.filter(function(li) { var numAttr = li.attributes.length; for(x=0;x<numAttr;x++) { var attr = li.attributes[x]; return attr['name'].test(regexp); } }); return matches; };
In elements , skip only those elements that you want to check, possibly selected through $$ . If you want to check all the elements in a container element, replace the elements with container and container.getChildren() in each instance of element above.
Julian H. Lam
source share