diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 78a7798..6dbe9d3 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -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) { @@ -653,6 +657,10 @@ export default class HTMLElement extends Node { } return `${name}=${val}`; }).join(' '); + // Update this.id + if (key === 'id') { + this.id = value; + } } /** diff --git a/test/112.js b/test/112.js index f93eca6..263cab6 100644 --- a/test/112.js +++ b/test/112.js @@ -14,4 +14,26 @@ describe('pull/112', function () { el.getAttribute('id').should.eql('id') el.toString().should.eql('
'); }); + it('#removeAttribute()', async function () { + const html = '
'; + 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('
'); + }); + it('#setAttribute()', async function () { + const html = '
'; + 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('
'); + }); });