CCode for Artists - Miles DeCoster

jQuery eq( ) and index( )

Two related jQuery functions:
eq() returns a jQuery object/selection when passed an index number;
index() returns the index number when passed a jQuery object/selection.

Typical use and syntax:
if ($('div p').index(this)==1){ // index() returns the index number of 'this'
	$(this).css('color', 'red');
}
$('div p').eq(3).css('color', 'blue'); // eq() returns the 'div p' DOM element at index 3

Paragraphs in divs:


0

1 jQuery index() selection

2

3 jQuery eq() selection

4


0

1 jQuery index() selection

2

3

4


Paragraphs not in divs:

0

1

2

3

4