Article From:https://www.cnblogs.com/xianya/p/9959920.html

  :eq(index)

Summary

    Matching an element with a given index value

parameter

    index  Counting from 0

    :gt(index)

Summary

    Match all elements larger than a given index value

parameter

    index  Counting from 0

   :lt(index)

Summary

    Match all elements less than a given index value

parameter

    index  Counting from 0

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="js/jquery-3.1.1.min.js" ></script>
        <title></title>
        <script>
            $(document).ready(function(){
                //Matching an element with a given index value
                $("li:eq(2)").css('color','#FF0000');
                //Match all elements larger than a given index value
                $("li:gt(2)").css('color','#0000FF');
                //Match all elements less than a given index value
                $("li:lt(2)").css('color','#FF00FF');
            });            
        </script>
    </head>
    <body>
        <ol>
            <li>Java</li>
            <li>C#</li>
            <li>HTML</li>
            <li>JavaScript</li>
            <li>C++</li>
        </ol>
    </body>
</html>

 

Leave a Reply

Your email address will not be published. Required fields are marked *