jquery - Load html templates to JavaScript variable -


i saving html templates single file. file contains loads of templates (more 50).

<script type="text/html" id="template-1">     <p>template 1</p> </script> <script type="text/html" id="template-2">     <p>template 2</p> </script> 

i need load templates js variable.

i have looked @ jquery load method loads template attach dom not need here.

any jquery or angularjs solution work me.

you can make regular ajax call using $.get , filter out elements response (without attaching dom).

for example

 $.get("templateurl", function (data) {    var $doc = $(data);    var firsttemplate= $doc.filter('#template-1').html()    var secondtemplate e= $doc.filter('#template-2').html()      //..load rest of templates variables  }); 

Comments