Using jQuery, you can get the name and values of all attributes for a specific element:
var obj = {};
var attribs = $('#elem')[0].attributes;
for (var i = 0; i < attribs.length; i++) {
obj[attribs[i].name] = attribs[i].value;
}
Remember to replace '#elem'with a valid selector for the element from which you want to get the attributes.
source
share