/ Published in: jQuery
                    
                                        
Select the first and last item in an unordered list. As an example, I add a CSS class to each.
In WordPress, it's not so easy to get wp\_list\_pages() to generate these classes. jQuery provides an easy out for javascript-enabled clients.
                In WordPress, it's not so easy to get wp\_list\_pages() to generate these classes. jQuery provides an easy out for javascript-enabled clients.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<!-- The sort of markup generated by wp_list_pages(), but common elsewhere. -->
<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">
jQuery( document ).ready( function ( $ ) {
// Add first and last menu item classes
$('ul.menu li:first-child').addClass( 'first_item' );
$('ul.menu li:last-child').addClass( 'last_item' );
});
</script>
URL: http://docs.jquery.com/Selectors/firstChild
Comments
 Subscribe to comments
                    Subscribe to comments
                
                