Created
March 13, 2014 14:55
-
-
Save arv/9529994 to your computer and use it in GitHub Desktop.
Implementation of createAttributeNS and setAttributeNodeNS
This file contains hidden or 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 (!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; | |
}; | |
} |
This file contains hidden or 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 (!Element.prototype.setAttributeNodeNS) { | |
Element.prototype.setAttributeNodeNS = Element.prototype.setAttributeNode; | |
} |
This file contains hidden or 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
removeAttributeNode is also removed from http://dom.spec.whatwg.org/