Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define jQuery "eq"

Tags:

jquery

I am having a difficult time wrapping my head around the jQuery eq. Can someone explain its use to me? What and how does it index?

thanks.

like image 801
superUntitled Avatar asked Sep 15 '09 17:09

superUntitled


People also ask

What is the difference between eq () and get () methods in jQuery?

eq() returns it as a jQuery object, meaning the DOM element is wrapped in the jQuery wrapper, which means that it accepts jQuery functions. . get() returns an array of raw DOM elements. You may manipulate each of them by accessing its attributes and invoking its functions as you would on a raw DOM element.

What is jQuery syntax?

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s). Basic syntax is: $(selector).action() A $ sign to define/access jQuery. A (selector) to "query (or find)" HTML elements. A jQuery action() to be performed on the element(s)

What is eq CSS?

:eq() is letting you know which element in row we are looking for (this is starting from 0). If you have a list with many “li” elements, then the first will be referred to as li:eq(0). So the CSS selector: html > body > div:eq(0) > ol > li > h3 > a:eq(1)

What is $() in jQuery?

In the first formulation listed above, jQuery() — which can also be written as $() — searches through the DOM for any elements that match the provided selector and creates a new jQuery object that references these elements: 1. $( "div.


1 Answers

With this HTML:

<ul>
    <li>Mario</li>
    <li>Luigi</li>
    <li>Princess</li>
    <li>Toad</li>
</ul>

And this JavaScript:

alert($("ul li").eq(0).text()); // Mario
alert($("ul li").eq(1).text()); // Luigi
alert($("ul li").eq(2).text()); // Princess
alert($("ul li").eq(3).text()); // Toad
like image 180
jimyi Avatar answered Sep 20 '22 03:09

jimyi