Net-informations.com
SiteMap  | About    

jQuery Traversing Methods



jQuery provides a variety of methods that allow us to traverse the DOM. Traversing can be broken down into three basic parts: parents, children, and siblings. jQuery has an abundance of easy-to-use methods for all these parts.

Get all children elements

To get all the children element of an parent element, children() method can be used.

Syntax

The optional selector this method accepts, is used to filter the children.

run this source code Try it Yourself
  • Red
  • Blue
  • Green


Full Source

jQuery find() Method

The find() method returns descendant elements of the selected element.

Syntax

A descendant is a child, grandchild, great-grandchild, and so on.

run this source code Try it Yourself
  • Red
  • Blue
  • Green


Full Source

jQuery children() Vs. find()

The children() only looks at the immediate children of the node, while find() traverses the entire DOM below the node, so children() should be faster given equivalent implementations. However, find() uses native browser methods, while children() uses JavaScript interpreted in the browser.

Get li attribute without using children() or find()

run this source code Try it Yourself
  • Red
  • Blue
  • Green


Full Source









net-informations.com (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.