Table of Contents
DOM Access in Jquery: Access the DOM in Jquery is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
jQuery is a very powerful tool. It provides various DOM access methods (DOM Traversal Method), which helps us to select elements in a document randomly or in a continuous manner.
Most DOM Traversal Method does not modify jQuery objects and they help filter their elements from a document based on the given conditions.
Search for elements by index in jQuery
Consider the example below of a simple document with the following HTML content:
The JQuery Example
list item 1 list item 2 list item 3 list item 4 list item 5 list item 6
It will produce the following result:
- list item 1
- list item 2
- list item 3
- list item 4
- list item 5
- list item 6
Above, each list has its own index, and can be located using the eq (index) method as in the example below.
Each child element starts its index from 0, so list item 2 will be accessed using $ ("li"). Eq (1) and so on.
As an example,
Simple example after adding color to the third item list .
The JQuery Example