Adsense

How to select first and last child / element with JQuery


<ul class="menu">
  <li class="page_item">First Item</li>
  <li class="page_item">Second Item</li>
  <li class="page_item">Third Item</li>
  <li class="page_item">Last Item</li>
</ul>

<script type="text/javascript">
  $(function()
  {
    //Add css classes to first and last item in the html list
    $('ul.menu li:first-child').addClass('first_item');
    $('ul.menu li:last-child').addClass('last_item');
  });
</script>

newest questions on wordpress