Created
November 14, 2010 01:54
-
-
Save pdokas/675834 to your computer and use it in GitHub Desktop.
Iterate over all attributes in a DOM node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, """)+'"'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment