Published in: jQuery
|
|
|
URL: http://docs.jquery.com/Selectors/firstChild
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.
<!-- 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>
You need to login to post a comment.
