Skip to content

Commit

Permalink
Fix setAttributes / removeAttributes to affect this.id
Browse files Browse the repository at this point in the history
  • Loading branch information
usagizmo committed Apr 11, 2021
1 parent 2bee38f commit 0ab164a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/nodes/html.ts
Expand Up @@ -609,6 +609,10 @@ export default class HTMLElement extends Node {
}
return `${name}=${val}`;
}).join(' ');
// Update this.id
if (key === 'id') {
this.id = '';
}
}

public hasAttribute(key: string) {
Expand Down Expand Up @@ -653,6 +657,10 @@ export default class HTMLElement extends Node {
}
return `${name}=${val}`;
}).join(' ');
// Update this.id
if (key === 'id') {
this.id = value;
}
}

/**
Expand Down
22 changes: 22 additions & 0 deletions test/112.js
Expand Up @@ -14,4 +14,26 @@ describe('pull/112', function () {
el.getAttribute('id').should.eql('id')
el.toString().should.eql('<div id="id"></div>');
});
it('#removeAttribute()', async function () {
const html = '<div id="id"></div>';
const root = parse(html);
const el = root.firstChild;
el.id.should.eql('id')
el.getAttribute('id').should.eql('id')
el.removeAttribute('id')
el.id.should.eql('')
should.equal(el.getAttribute('id'), undefined);
el.toString().should.eql('<div></div>');
});
it('#setAttribute()', async function () {
const html = '<div></div>';
const root = parse(html);
const el = root.firstChild;
el.id.should.eql('')
should.equal(el.getAttribute('id'), undefined);
el.setAttribute('id', 'id')
el.id.should.eql('id')
el.getAttribute('id').should.eql('id')
el.toString().should.eql('<div id="id"></div>');
});
});

0 comments on commit 0ab164a

Please sign in to comment.