JSFiddle - React, Tailwind, and code Playground
HTML
<form id="form_id" action="#">
<a data-prefix-age="22">22</a>
<a data-prefix-weight="82">82</a>
<a data-prefix-foo="82">82</a>
<a href="#">meh</a>
</form>
JavaScript
$(function(){
// retrieve all elements within the `#form_id` container
var $formElements = $("form#form_id > *");
var selectedElements = [];
// iterate over each element
$formElements.each(function(index,elem){
// store the JavaScript "attributes" property
var elementAttr = $(this)[0].attributes;
// iterate over each attribute
$(elementAttr).each(function(attIndex,attr){
// check the "nodeName" for the data prefix
if (attr.nodeName.search('data-.*') !== -1){
// we have found a matching element!
if (selectedElements.length < 2){
selectedElements.push(elem);
}
}
});
});
console.log(selectedElements);
});