Skip to content

Instantly share code, notes, and snippets.

@arv
Created March 13, 2014 14:55
Show Gist options
  • Select an option

  • Save arv/9529994 to your computer and use it in GitHub Desktop.

Select an option

Save arv/9529994 to your computer and use it in GitHub Desktop.
Implementation of createAttributeNS and setAttributeNodeNS
if (!Document.prototype.createAttributeNS) {
Document.prototype.createAttributeNS = function(namespaceURI, qualifiedName) {
var dummy = this.createElement('dummy');
dummy.setAttributeNS(namespaceURI, qualifiedName, '');
var attr = dummy.attributes[0];
dummy.removeAttributeNode(attr);
return attr;
};
}
if (!Element.prototype.setAttributeNodeNS) {
Element.prototype.setAttributeNodeNS = Element.prototype.setAttributeNode;
}
var attr = document.createAttributeNS('http://www.w3.org/1999/xlink', 'href');
attr.nodeValue = 'http://example.com';
console.dir(attr);
var test = document.createElement('test');
test.setAttributeNodeNS(attr);
console.dir(test);
@zcorpan
Copy link
Copy Markdown

zcorpan commented Apr 15, 2014

removeAttributeNode is also removed from http://dom.spec.whatwg.org/

@zcorpan
Copy link
Copy Markdown

zcorpan commented Apr 15, 2014

(Use removeAttributeNS instead)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment