JSFiddle - React, Tailwind, and code Playground

by Jay Scott. ANDERSON

HTML

<div attName:someOtherValue="12" id="test"> </div>

JavaScript

console.log(match_attribute(document.getElementsByTagName('div')[0], 'attName:'))

function match_attribute (elem, key) {
    var attributes = elem.attributes
    var obj = {}
    
    Array.prototype.slice.call(attributes).forEach(function(attribute) {
        if ( -1 !== attribute.name.indexOf(key.toLowerCase()) ) {
            obj = { name: attribute.name, value: attribute.value }
        }
    })
    return obj
}