eq in jquery


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');

<!DOCTYPE html>
  <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');

  <div class="Container">
    <button type="button" class="btnClick">Click</button><br />
  • One
  • Tow
  • Three
  • Four
  • Five

No comments :

Please Give Your Feedback