2

I study jquery, but i have a little confusion about this code :

var list = mylist.filter(function(f) {
    return $(f)
        .find('.anthing')
        .length > 0;
});

what does $(f) mean?

4
  • api.jquery.com/filter Commented Aug 18, 2016 at 9:05
  • points to mylist element Commented Aug 18, 2016 at 9:05
  • filter method loop through all elements in array and give you callback for each item to test, that callback parameter is item in the array Commented Aug 18, 2016 at 9:06
  • What is mylist ? An array or jQuery-object ? Commented Aug 18, 2016 at 9:26

2 Answers 2

2

Your mylist is an array or array like object. The f in the parameters is the single item in your myList.It calls the function for every item in the myList.Then it wraps your f into jQuery object and then the .find() will be visible on your object

Sign up to request clarification or add additional context in comments.

4 Comments

OP is asking what is f
@Rayon He asks $(f) not f
Isn't f part of $(f) ?
I can know what is f but not what is $(f)
0

It is the index passed through the function, which indicates the 0-based position of the element within the unfiltered set of matched elements.

In your case $(f) is useless since it represent $(0) || $(1) which does not represent a selection.

Comments

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.