` element (index `1`) in a document. ```html
This is the first paragraph (index 0).
This is the second paragraph (index 1).
This is the third paragraph (index 2).
``` ### Example 2: Using Negative Indexing You can pass a negative integer to target elements starting from the end of the matched set. ```javascript // Selects the second-to-last paragraph in the document $("p:eq(-2)").css("font-weight", "bold"); ``` --- ## Considerations and Best Practices ### 1. Performance Alternative: `.eq()` Method While the `:eq()` pseudo-class selector is highly convenient, it is a jQuery extension and not part of the CSS specification. Because of this, queries using `:eq()` cannot take advantage of the performance boost provided by the native DOM `querySelectorAll()` method. For optimal performance, especially in large documents, it is recommended to use the jQuery `.eq()` method instead: ```javascript // Instead of this: $("p:eq(1)").css("background-color", "yellow"); // Use this for better performance: $("p").eq(1).css("background-color", "yellow"); ``` ### 2. CSS3 Alternative: `:nth-child()` If you prefer to stick to standard CSS selectors, you can use the `:nth-child()` selector. However, keep in mind that `:nth-child()` is **1-based**, whereas `:eq()` is **0-based**. ```javascript // These two statements target the same element: $("p:eq(1)"); // jQuery 0-based index (2nd element) $("p:nth-child(2)"); // Standard CSS 1-based index (2nd element) ```
YouTip