I have a component that can be used several times on a page. And I would like to save the configuration of HTML and components.
<div id="myComponent">
<table>
<th>c1</th>
...
<th>cX</th>
</table>
</div>
<script>
var componentApi = new MyModule.MyComponent($('#myComponent')[0]);
</script>
But I am not happy with that. Firstly, because I don’t like to refer to the uniqueness of id (this makes the template complex), and secondly, I don’t like the unnecessary search for the identifier through the entire document.
But my all alternative ideas don't work:
- I do not want to rely on
scriptid either (to calculate the previous brother) for the same reasons. - And
.currentScriptdoes not work in IE 11. Divhas no event onLoad...
Do we have a better solution than searching for an identifier throughout the document, if only what we need initializes the component in HTML with an HTML layer?
. , HTML JS DRY. "". , -, data-, HTML. , HTML - HTML.
. , , " " ( ) "" . id . , , id HTML/DOM, , , id.
. , ( , ). " " + "-" , , - , Polymer polyfill?