JSFiddle - React, Tailwind, and code Playground

HTML

<div data-foo="1"></div>
<div></div>

JavaScript

var $result = $('*').filter(function(){

    var ret = false;
    
    $.each(this.attributes, function() {
        
        if(/^data-/.test(this.nodeName)){
           ret = true;
           return false; //to break the loop
        }
    });
    
    return ret;
});
    
$result.text('I have a data attribute');