JSFiddle - React, Tailwind, and code Playground
by salt
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-compat/3.0.0-alpha1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div data-bg-check="images">
</div>
<div data-bg-check="images">
</div>
<div data-bg-check="poop">
</div>
JavaScript
var hash = [];
$("[data-bg-check]").each(function (i, div) {
$.each($(div), function (j, obj) {
var attr = obj.getAttribute('data-bg-check');
if (!(attr in hash)) hash[attr] = [];
hash[attr].push(div);
});
});
console.log(hash)