I am using the jquery-tmpl template library to build a dynamic <select>
list. In my template I have a function call that returns all <option>
elements from an existing <select>
element on the page.
In my template the function call executes successfully and returns the .html()
from the existing <select>
list but renders it as text in the DOM rather than appending the HTML to the <select>
list.
I understand that my function is only returning a string and looks to be treated as such, but I don t know how to actually get a reference to the <select>
element in the template to execute any jQuery functionality on.
How do I append the <option>
list to the template HTML element, or get a reference to the template element?
Here is my template:
<script id="searchTemplate" type="text/x-jquery-tmpl">
<select id="destinations" class="destinations">
${getDestinationList()}
</select>
</script>
And my function to return the <option>
collection as a string:
function getDestinationList(){
return $("#tabs-0 select[id$= destinations ]").html(); //returns HTML list as string successfully
}
Thanks in advance!!