polymer - Is there a way to specify an HTML5 custom element should be used only once per document? -
polymer - Is there a way to specify an HTML5 custom element should be used only once per document? -
i searched around on google, here on stackoverflow, probably-now-outdated html5 spec's, , have not found answer. sense though i'm missing obvious.
i'm wondering if there way specify when creating html5 custom element, users of new element should (or must, 'valid' element's spec) utilize 1 time per document?
for illustration html's elements, 'head', 'body', 'main', etc., should used 1 time within document. have not been able find way custom elements. possible, either vanilla html5, polymer, or other means?
thanks can help.
use built-in callbacks track usage of custom element:
var myelementprototype = object.create(htmlelement.prototype); myelementprototype.len = 0; myelementprototype.attachedcallback = function() { myelementprototype.len++; if (myelementprototype.len > 1) { alert('the document not valid'); // } }; myelementprototype.detachedcallback = function() { myelementprototype.len--; }; document.registerelement( 'my-element', { prototype: myelementprototype } );
html5 polymer
Comments
Post a Comment