eq(index)
The eq() method obtains the single indexed element in the wrapped set elements. As we know that index start from 0, so if you pass 0 in eq() method it will return the first DOM element and if you pass 1 it will return second DOM element and so on.$('ul').find('li:eq(2)').css('background-color', 'Red');
CODE
<!DOCTYPE html> <html> <head> <title>jQuery With Example</title> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('.btnClick').click(function () { $('ul').find('li:eq(2)').css('background-color', 'Red'); }); }); </script> </head> <body> <div class="Container"> <ul> <li>One</li> <li>Tow</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul> <button type="button" class="btnClick">Click</button><br /> </div> </body> </html>
DISPLAY
- One
- Tow
- Three
- Four
- Five
No comments :
Please Give Your Feedback