Skip to content

Commit

Permalink
Add hasAttributeNS & co
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Dec 31, 2022
1 parent 2f090ba commit d540a4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Expand Up @@ -250,6 +250,12 @@ function unescFn(ent, hex, num) {
return num ? String.fromCharCode(parseInt(num, hex === "" ? 10 : 16)) : unescMap[ent] || ent
}

;["hasAttribute", "getAttribute", "setAttribute", "removeAttribute"].forEach(function(name) {
Element[name + "NS"] = function(ns, a, b) {
return this[name].call(this, a, b)
}
})


function Attr(node, name) {
this.ownerElement = node
Expand Down Expand Up @@ -321,9 +327,6 @@ extendNode(HTMLElement, Element, {
localName: null,
tagName: null,
styleMap: null,
setAttributeNS: function (namespace, name, value) {
this.setAttribute(name, value)
},
focus: function() {
this.ownerDocument.activeElement = this
},
Expand Down
5 changes: 5 additions & 0 deletions test/index-spec.js
Expand Up @@ -76,8 +76,13 @@ describe("DOM lite", function() {

it("can set attributes with namespace", function (assert) {
var el = document.createElementNS(null, "use")
assert.equal(el.getAttributeNS(null, "xlink:ref"), null)
el.setAttributeNS(null, "xlink:ref", "http://localhost")
assert.equal("" + el, '<use xlink:ref="http://localhost"></use>')
assert.equal(el.hasAttributeNS(null, "xlink:ref"), true)
el.removeAttributeNS(null, "xlink:ref", "http://localhost")
assert.equal("" + el, '<use></use>')
assert.equal(el.hasAttributeNS(null, "xlink:ref"), false)

assert.end()
})
Expand Down

0 comments on commit d540a4d

Please sign in to comment.