medikoo/domjs

Add arbitrary HTML elements?

ProdigySim opened this issue · 2 comments

Hi, is there a way for me to add arbitrary custom elements? I like to use semantic tagging and I'd like to be able to do something like:

myCustomElement("content") --> <my-custom-element>content</my-custom-element>

Yes, you can do it via:

var myCustomElement = domjs.ns.myCustomElement = domjs.ns.element.bind(domjs, 'my-custom-element');

Optionally you may also provide some custom constructor or methods for that element:

// This has to be defined before any `my-custom-element` is created by domjs
require('domjs/ext')['my-custom-element'] = {
  _construct: function (/* constuctor args */) {},
  methodA: function () { ... }
};

I'll keep it open, until I include this information in documentation

Very cool! Thanks for this project, there are a lot of cool patterns available with it.