Skip to content

Instantly share code, notes, and snippets.

@pdokas
Created November 14, 2010 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdokas/675834 to your computer and use it in GitHub Desktop.
Save pdokas/675834 to your computer and use it in GitHub Desktop.
Iterate over all attributes in a DOM node
if (node.attributes.length) {
// Get the known-existent list of attributes and iterate over them
var attrs = node.attributes;
for (var length = attrs.length, i = 0; i < length; i++) {
// IE 5-8 (all currently shipping versions) always list all possible attributes, specified or not.
// The "specified" member of each attribute indicates whether it was existent in the HTML and is required for the purpose here.
// IE will also report the unique jQuery identifiers as well as jQuery's sizzle engine cache attributes, so parse those out entirely.
if (attrs[i].specified
&& attrs[i].nodeName.indexOf('jQuery') == -1
&& attrs[i].nodeName.indexOf('sizcache') == -1
&& attrs[i].nodeName.indexOf('sizset') == -1) {
// Ensure quotes won't break the string and add the now parsed attribute to the array
xml_array.push(' '+attrs[i].nodeName+'="'+attrs[i].nodeValue.replace(/\"/g, "&#34;")+'"');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment