I want to put all attributes in a Html element into an array: like i have a jQuery Object, whichs html looks like this:
Try something like this
and then get all attributes
const foo = document.getElementById('foo');
// or if you have a jQuery object
// const foo = $('#foo')[0];
function getAttributes(el) {
const attrObj = {};
if(!el.hasAttributes()) return attrObj;
for (const attr of el.attributes)
attrObj[attr.name] = attr.value;
return attrObj
}
// {"id":"foo","[href]":"url","class":"","(click)":"alert('hello')","data-hello":"world"}
console.log(getAttributes(foo));
for array of attributes use
// ["id","[href]","class","(click)","data-hello"]
Object.keys(getAttributes(foo))