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
selects only first level elements of type <p> while $(“div > p”) selects all
paragraphs including first level and sub levels.
be used to select multiple types of child elements unlike $(“div > p”). e.g. $(“div”).children(“p,
2. 2. $(“div”).children()
Both select children of specified
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.
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
travels up to the tree until it finds the matched element
while .parents() travels up to the
return zero or one element. While .parents() returns zero, one or more than one elements.
5. 5. .find() and .filter()
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
.find() travels up to all
level down while .children() travels
only one level down.
7. 7. .parent() and .parents()
Both search for its parent
only single level up the DOM tree while .parents()
travels up to the root of DOM tree.