jQuery .eq() Examples

Welcome To jQuery !!
+_+
Example 1
View
Source
<style type="text/css">
    .css_test {
        margin-top:10px;
    }
    .css_test img {
        width:80px;
    }
</style>

<button type="button" onclick="j_test(0)">First Face !!</button>
<button type="button" onclick="j_test(1)">Second Face !!</button>
<button type="button" onclick="j_test(2)">Third Face !!</button>
<div class="css_test">
    <img src="http://biketago.com/img/etc/huk1.gif" />
    <img src="http://biketago.com/img/etc/huk1.gif" />
    <img src="http://biketago.com/img/etc/huk1.gif" />
</div>

<script type="text/javascript">
    function j_test(n){
        $( '.css_test img' ).eq( n ).attr('src', 'http://biketago.com/img/etc/huk2.gif');

        setTimeout(function(){
            $( '.css_test img' ).eq( n ).attr('src', 'http://biketago.com/img/etc/huk1.gif');
        }, 1000);
    }
</script>
jQuery

$( selector ).eq( number )

$( selector ).eq( 0 )
$( selector ).eq( 1 )

Example 2
Use Negative Numbers
View
Source
<style type="text/css">
    .css_test {
        margin-top:10px;
    }
    .css_test img {
        width:80px;
    }
</style>

<button type="button" onclick="j_test(-1)">eq( -1 )</button>
<button type="button" onclick="j_test(-2)">eq( -2 )</button>
<button type="button" onclick="j_test(-3)">eq( -3 )</button>
<button type="button" onclick="j_test(-4)">eq( -4 )</button>
<button type="button" onclick="j_test(-5)">eq( -5 )</button>
<div class="css_test">
    <img src="http://biketago.com/img/etc/huk1.gif" />
    <img src="http://biketago.com/img/etc/huk1.gif" />
    <img src="http://biketago.com/img/etc/huk1.gif" />
    <img src="http://biketago.com/img/etc/huk1.gif" />
    <img src="http://biketago.com/img/etc/huk1.gif" />
</div>

<script type="text/javascript">
    function j_test(n){
        $( '.css_test img' ).eq( n ).attr('src', 'http://biketago.com/img/etc/huk2.gif');

        setTimeout(function(){
            $( '.css_test img' ).eq( n ).attr('src', 'http://biketago.com/img/etc/huk1.gif');
        }, 1000);
    }
</script>
jQuery

$( selector ).eq( Negative Numbers )

$( selector ).eq( -1 )
$( selector ).eq( -2 )

jQuery .eq() Documentation : http://api.jquery.com/eq/