JSFiddle - React, Tailwind, and code Playground

HTML

<span data-one="1">something</span>

<br/>
<span>something</span>

<br/>
<span data-two="2">something</span>

<br/>
<span>something</span>

<br/>

JavaScript

function getAllDataElements() {
    //get all DOM elements
    var elements = document.getElementsByTagName("*");
    //array to store matches
    var matches = [];
    //loop each element
    for (var i = 0; i < elements.length; i++) {
        var element = elements[i];
        //get all attributes for the element and loop them
        var attributes = element.attributes;
        for (var j = 0; j < attributes.length; j++) {
            //get the name of the attribute
            var attr = attributes.item(j).nodeName;
            //check if attibute name starts with "data-"
            if (attr.indexOf("data-") == 0) {
                matches.push(element); //add it to matches
            }
        }
    }
    return matches; //return results
}

var results = getAllDataElements();

//you can then use your array of matches
results.forEach(function (i) {
    i.style.color = "#FF0000";
});