Passing a block of html to jQuery function
I am new to jQuery and trying to figure out the sample code below:
- var taskTemplate = '<li class="task"><input class="complete" type="checkbox" /> <input class="description" type="text" placeholder="Enter task description..." /> <button class="delete-button">Delete</button></li>';
- function _renderTask(task) {
- var $task = $(taskTemplate);
- if(task.complete) {
- $task.find(".complete").attr("checked", "checked");
- }
- $task.find(".description").val(task.description);
- return $task;
- }
My question is that on line 4 the whole block of html for tasktemplate variable is passed to jQuery function for selection. I am used to seeing only class or id passed to $ function. What is this trying to accomplish?
Also, i wanted to know when task.complete would return true?