...">

What is the expected behavior of removing the is = "" attribute from a Custom Element?

For instance,

Suppose we have <div is="awesomebutton"></div>a user element definition:

document.registerElement('awesomebutton', AwesomeButton)

What is the expected behavior when an attribute is=""is removed or replaced with a new value?

+4
source share
1 answer

In section 7 of the last specification of the working draft (February 26, 2016), it should not affect the type of element:

After you create an instance of a user element, changing the attribute value is should not affect this element type of the user element.

attributeChangedCallback . ( is .) (Chrome Firefox dom.webcomponents.enabled):

'use strict';

const prototype = Object.create(HTMLElement.prototype);
prototype.attributeChangedCallback = function(name, oldValue, newValue) {
  this.textContent = `my "${name}" attribute changed to "${newValue}"!`; 
};

document.registerElement('examp-el', {prototype: prototype, extends: 'div'});

const el = document.createElement('div', 'examp-el');
el.textContent = "I'm an element!";

document.body.appendChild(el);
el.setAttribute('is', "changed once");
el.removeAttribute('is');
el.setAttribute('is', "changed twice");
el.setAttribute('is', "changed thrice");
Hide result

, , , . - 2.3 ( 17 2016 ):

is .

+6

All Articles