Similiar JQuery Selector and Traversers

By Atul Kumar Jul 25, 2012
Some JQuery selectors are having same functionality with little but noticeable differences which can be useful while working with JQuery.

Similar but Different JQuery Selectors

While working with JQuery, there could be some selectors and manipulation methods which seems having same functionality but they are also having some difference which I described below:

1.    1. $(“div”).children() and $(“div > p”)


Both select children of paragraph <p>.


$(“div”).children(“p”) selects only first level elements of type <p> while $(“div > p”)  selects all paragraphs including first level and sub levels.

$(“div”).children() can be used to select multiple types of child elements unlike $(“div > p”). e.g. $(“div”).children(“p, span, div”).

2.     2. $(“div”).children() and $(“div”).contents()


Both select children of specified element.


.children() selects element nodes only but .contents() also selects text nodes written inside elements.

3.     3. :eq and .eq()


             Both selects the elements placed at specified index value.


.eq() accepts negative value while :eq() does not. Providing negative value say -1 to .eq() selects the last element.

4.     4. .closest() and .parents()


Both traverse up to the DOM tree.


.closest() travels up to the tree until it finds the matched element while .parents() travels up to the root element.

.closest() return zero or one element. While .parents() returns zero, one or more than one elements.


5.     5. .find() and .filter()


Both refine the selection of selected elements.


.find() selects the descendents of selected elements while .filter() further refine the selection of selected elements in the result by means of applied JQuery selector expression or callback functions.

6.     6. .find() and .children()


             Both refine the selection of their child elements.


            .find() travels up to all level down while .children() travels only one level down.

7.     7. .parent() and .parents()


Both search for its parent elements.


.parent() travels only single level up the DOM tree while .parents() travels up to the root of DOM tree.








Atul Kumar

I am software developer and I love to work with microsoft technologies.I develop web applications, Web Services, Windows phone applications and database. I always love to explore new technologies.



Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs