Quantcast
Channel: How to get element from template by javascript? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How to get element from template by javascript?

$
0
0

I dont know good method how to get DOM element from template by javascript.

Example template:

<script id = "template" type="text/template"><div>text1</div><div>text2</div><div>text3</div></script>

For example i want get div with "text2"

There is ways which i know, all of them are bad:

  1. Add "class" to all elements - it breaks semantics (class created for CSS). In big projects you must use very long names for classes, its very inconvenient.

  2. Get element by his number (index) - when adding a new element, you must rewrite old numbers in your code.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images