Open Laboratory for Technocrats

Grab the developer role, learn concepts & prepare with senior software engineers to get solutions for problems in a software job. Coding and Programming Solutions crafted for you.

Parent vs Closest - JavaScript

When we usually work with javascript then we use the searching with the help of closest or parent or parents.

Lets discuss something about them as:

closest() : 
* Begins with the current element
* Traverses up the DOM tree and if found the first selector stops there
parent() : 
* Begins with the current element
* Traverses up to just parent in DOM tree and if found the selector stops there
parents() : 
* Begins with the current element
* Traverses up to complete DOM tree and found all selectors and returns all the set

Here are some speed results from jsperf



Top #3 Articles

Most Read