You can declare a subclass of DivElement as follows:
import 'dart:html';
class MyDiv extends DivElement {
factory MyDiv() => new Element.tag('div', 'my-div');
MyDiv.created() : super.created();
}
A factory constructor is not required, but it is convenient if you want to build instances imperatively.
Then you must register your custom element with the document before you can create it:
main() {
document.register('my-div', MyDiv, extendsTag: 'div');
document.body.append(new MyDiv()..text = 'Hello');
}
Dartium , Custom Elements (, Chrome 33+). polyfill. pubspec:
dependencies:
custom_element: '>=0.9.0'
...
pub get polyfill script html:
<body>
<script src="packages/custom_element/custom-elements.min.js"></script>
...
</body>