Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Method eq() in jquery

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 315
    Comment on it

    Description:
    The eq ( index ) method reduces the set of matched elements to a single element or we can say that find the element that matches or equals the index provided.

    Syntax:
    Here is the simple syntax to use this method:

    selector.eq ( index )

    Parameters:
    index: This is the position of the element in the set of matched elements, starting at 0 and going to length 1,2,3...or -1,-2,-3....

    Note:
    In mathematice we studied the set of integers (....-3,-2,-1,0,1,2,3....) in it there are positive and negative integers including 0. When we make index on many div (s) and li (s) we should understand integers.we can take positive integer like 0,1,2,3... and negative integers like -1,-2,-3...

    Example:
    Following is a simple example which adds the color to fouth list item. We index on li of number 4 will be yellow in color. So we take index eq(3) because integers starts for 0,1,2,3,4.It means the 4th element will be coloured in yellow. or Method reduces three elements (0,1,2,3) and 4th element is coloured.

    HTML:-

     <!DOCTYPE html>
       <html>
       <head><title></title>
       <link href="style.css" type="text/css" rel="stylesheet" />
       <script type="text/javascript" 
                   src="/jquery/jquery-1.3.2.min.js"></script>
       <script type="text/javascript" language="javascript">
       <script>
         $(document).ready(function(){       
             $( "body" ).find( "div" ).eq( 3 ).addClass( "yellow" );       
         });    
       </script> 
    
        </head>
        <body>    
        <div>0</div>
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
        <div>8</div>
        <div>9</div>
        <div>10</div>
        </body>
        </html>
    

    CSS:-

      *{
        padding:0px;
        margin:0px;
        }
        .body{
            font:14px/1 arial,helvetica,sans-serif;
        }
         div {
        width: 20px;
        height: 20px;
        margin: 10px;
        float: left;
        padding:10px;
        border-radius:50%;
        border: 3px solid red;
        }
        .yellow {
        background: yellow;
        }
    
    Method eq() in jquery

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: