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?
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()
...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With