Skip to content

Instantly share code, notes, and snippets.

@arv
Created March 13, 2014 14:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arv/9529994 to your computer and use it in GitHub Desktop.
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);
@RathoreShubham
Copy link

Great work working .... saved me :-)

@zcorpan
Copy link

zcorpan commented Apr 15, 2014

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

@zcorpan
Copy link

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