lessthan selector in jQuery with example

Less Than selector returns a list of element with index less than specified index.

Example :

    <title>less Selector</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
    <script type="text/javascript">
    $("ul li:lt(2)").css({'font-size':'20px','background-color':'Orange'});
    <ul type="square">
    <li>Cesc Fabregas</li>
    <li>Thierry Henry</li>
    <li>Lionel Messi</li>
    <li>Zinedine Zidane</li>
    <button id="myButton">Click Me</button>
    <button onclick="location.reload()">Reset</button>

Demo :

In the above example, we have used less than selector. Less Than selector select a list of elements with the index less than specified index. In above example, it selects the list elements with index less than 2 and applies CSS to it.


Post a Comment