What does jQuery .find()
method return? a object OR a array list of objects?
If it returns an object which contain all the matched elements. How to convert this object to an array?
If it returns a array of elements, why $(xml).find("DATE").sort(mySortFunc);
does not work, it seems the jQuery .find()
returns an object which can not apply Javascript sort()
method which is supposed to be applied on array.
Generally, I need to sort the objects find by $(xml).find("DATE")
, but when I use sort function, it raised an error that the object can not be resolved.
jQuery find() Method The find() method returns descendant elements of the selected element. A descendant is a child, grandchild, great-grandchild, and so on. The DOM tree: This method traverse downwards along descendants of DOM elements, all the way down to the last descendant.
find() returns an object even when there's no matching child element in the DOM.
The majority of jQuery methods returns a jQuery object, which can be accessed like it is an array (e.g. it has a .length
attribute, elements can be accessed using the square bracket notation ([0]
), and it supports some array methods (slice()
)).
jQuery has a method called toArray()
which can be used to convert the jQuery object to a real array.
You can also use get()
with no arguments to achieve the same effect (and save you a few key presses).
In future, you can checkout the jQuery API, and the return type for all jQuery methods is listed in the relevant documentation (e.g. for find()
, the return type is "jQuery")
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