Skip to content

Instantly share code, notes, and snippets.

@Skateside
Created April 1, 2014 09:00
Show Gist options
  • Save Skateside/9910539 to your computer and use it in GitHub Desktop.
Save Skateside/9910539 to your computer and use it in GitHub Desktop.
/**
* Creates a string of an element, showing the node name and all attributes.
* This is mainly useful for debugging in Internet Explorer where a DOM node
* representation isn't shown in the console.
*
* @param {Element} elem Element to stringify.
* @return {string} String representation of the element.
*/
function stringifyElem(elem) {
var str = '<' + elem.nodeName.toLowerCase(),
attrs = elem.attributes,
i = 0,
il = attrs.length,
attr = null;
while (i < il) {
attr = attrs.item(i);
str += ' ' + attr.nodeName + '="' + attr.nodeValue + '"';
i += 1;
}
return str + '>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment