2

I was given these set of practice instructions:

Write a selector which finds the UL within the tasks div and store this into a variable named task_list.

    var task_list = $('div#tasks ul');

then the next one got me confused:

Write a second selector line which finds all children within task_list that have the class name completed. Store this into a variable named all_completed. Use the detach() method. Call detach() on your all_completed variable.

     var all_completed = $(task_list).children('li.completed').detach();

or

   $(all_completed).detach(task_list);

Can someone please help me? Is this asking me to create a variable and use it as a selector in jQuery? If so, how do I do this??

1
  • I think your first version should work. Commented Jan 24, 2013 at 2:43

1 Answer 1

4

task_list is already a jquery object, you don't need to re-jquery (is that a term?) it.

var all_completed = task_list.children('li.completed').detach();
Sign up to request clarification or add additional context in comments.

3 Comments

I think jQuery determines pretty quickly that its argument is already a jQuery object, and just returns it. So there's little harm in re-jquerying.
I'm not understanding how task_list is already jQuery-ied.... Is it because I assigned it a jQuery statement? I thought making a jQuery variable was done $variable = ('variablenowjQuery');??
When you $(".anything") you are creating a jquery object using the selector, in this case .anything

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.