Skip to content

Instantly share code, notes, and snippets.

@bgrins
Created July 30, 2013 20:20
Show Gist options
  • Select an option

  • Save bgrins/6116556 to your computer and use it in GitHub Desktop.

Select an option

Save bgrins/6116556 to your computer and use it in GitHub Desktop.
Given a string convert it into an array of name/value objects
function escapeAttributeValues(attr, aAttrNode) {
let div = aAttrNode.ownerDocument.createElement("div");
div.innerHTML = "<div " + attr + "></div>";
var attributes=[];
var el = div.childNodes[0];
for (var i=0, l=el.attributes.length; i<l; i++){
let attr = el.attributes.item(i)
attributes.push({name:attr.nodeName, value: attr.nodeValue});
}
return attributes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment