Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a widget inside the "jquery-tmpl"?

I have to create a widget for the div which is inside the jquery-tmpl script.

<script id="movieTemplate" type="text/x-jquery-tmpl"> 
      <div id='name'>${Name}</div>
</script>

In the above script, I want to access the name div and create a widget.

Note: I am going to append that script in another widget, so here I don't know "what is the parent of this template".

How could I achieve this?

like image 941
BalaKrishnan웃 Avatar asked Jul 20 '12 09:07

BalaKrishnan웃


1 Answers

In the code you show, the string <div id='name'>${Name}</div> is inside a script node, so it is not translated into a DOM node, and you cannot access the div node before actually rendering the template.

You can render the node : $.tmpl(myTemplate, myData).appendTo(myDomElement), and then you can access the created node : $(myDomElement).find('div#name') and do whatever you want with it (e.g. : $(myDomElement).find('div#name').datepicker() ...)

like image 178
LeGEC Avatar answered Nov 02 '22 20:11

LeGEC