How can you do the equivalent to
document.querySelectorAll(\'[data-foo]\')
where query
Try this it works
document.querySelector('[attribute="value"]')
example :
document.querySelector('[role="button"]')
Try this - I slightly changed the above answers:
var getAttributes = function(attribute) {
var allElements = document.getElementsByTagName('*'),
allElementsLen = allElements.length,
curElement,
i,
results = [];
for(i = 0; i < allElementsLen; i += 1) {
curElement = allElements[i];
if(curElement.getAttribute(attribute)) {
results.push(curElement);
}
}
return results;
};
Then,
getAttributes('data-foo');