Skip to content

Commit

Permalink
Merge pull request #83 from canjs/update-class
Browse files Browse the repository at this point in the history
Element.setAttribute updates existing className
  • Loading branch information
andrejewski authored Dec 28, 2017
2 parents e73bb39 + 6d7f4b5 commit 8a23ed7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/simple-dom/document/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Element.prototype._setAttribute = function(_name, value) {
attr = attributes[i];
if (attr.name === name) {
attr.value = value;
const special = attrSpecial[name];
if(special) {
special(this, value);
}
return;
}
}
Expand All @@ -67,7 +71,7 @@ Element.prototype._setAttribute = function(_name, value) {
// a map and array
attributes[name] = value;

let special = attrSpecial[name];
const special = attrSpecial[name];
if(special) {
special(this, value);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/test/element-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ QUnit.test("setAttribute('class', value) updates the className", function(assert
assert.equal(el.className, "foo bar", "Element's className is same as the attribute class");
});

QUnit.test("setAttribute('class', value) updates an existing className", function (assert) {
var document = new Document();
var el = document.createElement("div");
el.setAttribute("class", "foo bar");
el.setAttribute("class", "baz foo");

assert.equal(el.className, "baz foo", "Element's className is updated");
});

QUnit.test("removeAttribute('class') updates the className", function (assert) {
var document = new Document();
var el = document.createElement("div");
Expand Down

0 comments on commit 8a23ed7

Please sign in to comment.