0

I have implemented basic template parser for javascript. it simply replaces variables within template string. i.e {event.date} will be 7/4/2013

I am using script tag to store template string

<script id="date_template" type="text/html"> <span class="date" id="date_{event.id}">  {event.date}  <span> </script> 

but it gives error in mobile devices so I have used div element for this

<div style="display:none" id="date_template"> <span class="date" id="date_{event.id}">  {event.date}  <span> </div> 

but it creates dom element which causes other problems. Is there any other way to do this?

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Rupesh Patel
  • 3,015
  • 5
  • 28
  • 49

1 Answers1

0

Here is another way to do this:

$("<span/>",  
   {
    "class":"date",
    "id":"date_$event.id".replace(/\$event.id/,event.id),
    "html":event.date
   }
 )

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265