Jerald
Jerald

Reputation: 4048

Polymer elements as attributes

Is it possible to inlude polymer elements using HTML attributes instead of HTML tags? For example:

<div some-polymer-behavior></div>

I think it is more convenient to use attributes than wrapping code into HTML tags if I want to decorate an existing element with some functionality.

Upvotes: 0

Views: 50

Answers (1)

Tomasz Pluskiewicz
Tomasz Pluskiewicz

Reputation: 3662

What you are looking for is extending native HTML elements.

Your element is

Polymer({
   is: 'my-div-extension',
   extends: 'div'
});

And the usage is

<div is="my-div-extension"></div>

Unfortunately, this comes with a few drawbacks, which you should be aware of:

  1. It's not standardized and likely to be obsolete before Web Components spec is finished.
  2. It is not (yet) possible to extend other Polymer elements
  3. It is not possible to extend multiple native elements in one go
    • A wrapper element would be a better fit
  4. You cannot apply multiple extensions to one tag like <div behavior-one behavior-two>

Upvotes: 2

Related Questions