Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post


jQuery .parents() method allows us to search through the ancestors of these elements in the DOM tree and construct a new jQuery object from the matching elements ordered from immediate parent on up.


a. If the filter parameter is empty, this function will select all ancestors of a set of elements.

b. Parents is similar to closest(), in that they both traverse up the DOM tree but difference is closest() returns the first ancestor that matches the passed exp ression up to DOM tree

but parents returns all ancestors that matches the passed exp ression for DOM tree.

Code sample:

//With filter parameter



//Without filter parameter


Share your answer

Share as a guest

Please subscribe me to the CodeChef4U.

By creating your new answer, you agree to the privacy policy and terms of service.