I have to generate some li element automatically and the way I was doing it it through a function that return text inside a loop, something like this:
function getLi(data) {
   return '<li>' + data + '</li>';
}
then I found a better way to do it by writing html inside a div:
<div style="display:none;" id="Template">
   <li id="value"></li>
</div>
and then I would change the id and value get the html and reset the element to original state:
var element = $("#value");
element.html(data);
element.attr('id', getNewId());
var htmlText = $("#Template").html();
element.html('');
element.attr('id', 'value');
return htmlText;
then I was reading on script template
and I figured this could be a better way of doing it,
However apply the previous code didn't work as the inner elements didn't exist according to this article
so how can I apply this?
EDIT: I put inside a ul tag, I use this method to get the items dynamically
EDIT2:
<li>
   <a href="#" >
   <span>
   <span>
some text
   </span>
   </span>
</li>
this isn't necessarily what I have but something along the way
Edit3: my ul does not exist orgialy it's generated dynamically I insist this is not a duplicate I want to know how to use a template with some dynamic variables
 
     
     
     
     
     
     
    
?](http://stackoverflow.com/questions/1145208/jquery-how-to-add-li-in-an-existing-ul)