From d540a4d5fe44bbc9b300a1cc34c462a7108391ec Mon Sep 17 00:00:00 2001 From: Lauri Rooden Date: Sat, 31 Dec 2022 04:15:55 +0200 Subject: [PATCH] Add hasAttributeNS & co --- index.js | 9 ++++++--- test/index-spec.js | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5fe8e82..c871474 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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 }, diff --git a/test/index-spec.js b/test/index-spec.js index 51ec498..ac7d961 100644 --- a/test/index-spec.js +++ b/test/index-spec.js @@ -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, '') + assert.equal(el.hasAttributeNS(null, "xlink:ref"), true) + el.removeAttributeNS(null, "xlink:ref", "http://localhost") + assert.equal("" + el, '') + assert.equal(el.hasAttributeNS(null, "xlink:ref"), false) assert.end() })