Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Get all an element's attributes & values as a matrix
// Return all attributes, optionally filtered by RegExp
$.fn.attrs = function(expr){
var
el = this[0],
$el = this,
attrArray = [];
for(var i=0, attrs = el.attributes; i<attrs.length; ++i){
var attrKey = [
attrs.item(i).nodeName,
attrs.item(i).nodeValue
];
if(!expr || expr.test(attrKey[0]))
attrArray.push(attrKey);
};
return attrArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment