Skip to content

Commit

Permalink
Fix setNamedItem signature
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Jul 5, 2024
1 parent 84915b4 commit 1a04ec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var boolAttrs = {
return attr ? attr.value : null
},
setAttribute: function(name, value) {
this.attributes.setNamedItem(name, value)
this.attributes.setNamedItem(new Attr(this, name, value))
},
removeAttribute: function(name) {
this.attributes.removeNamedItem(name)
Expand Down Expand Up @@ -299,11 +299,11 @@ NamedNodeMap.prototype = {
if (attr !== null) delete this[loName]
return attr
},
setNamedItem: function(name, value) {
this.removeNamedItem(name)
var loName = name.toLowerCase()
if (loName === "style") value = new CSSStyleDeclaration(value).cssText
this[loName] = new Attr(this.ownerElement, name, value)
setNamedItem: function(attr) {
var oldAttr = this.getNamedItem(attr.name)
if (attr.name === "style") attr.value = new CSSStyleDeclaration(attr.value).cssText
this[attr.name] = attr
return oldAttr
},
toString: function(minify) {
var map = this
Expand Down
3 changes: 2 additions & 1 deletion test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ describe("DOM lite", function() {
assert.equal(h1.matches("[ID3='']"), true)
h1.removeAttribute("id3")

h1.removeAttribute("id2")
assert.own(h1.attributes.removeNamedItem("id2"), {name: "id2", value: "321"})
assert.equal(h1.attributes.removeNamedItem("id2"), null)
assert.equal(h1.getAttribute("id"), "123")
assert.equal(h1.getAttribute("id2"), null)
assert.equal(h1.attributes.length, 1)
Expand Down

0 comments on commit 1a04ec5

Please sign in to comment.