Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created December 10, 2009 10:19
Show Gist options
  • Save nojimage/253256 to your computer and use it in GitHub Desktop.
Save nojimage/253256 to your computer and use it in GitHub Desktop.
jquery.markup_first_last.js
/**
* jQuery Markup First and Last Plugin
*
* Copyright 2009, nojimage (http://php-tips.com/)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @version 1.0
* @author nojimage <nojimage at gmail.com>
* @copyright 2009 nojimage
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://php-tips.com/
* @modifiedby nojimage <nojimage at gmail.com>
*
* Usage:
*
* <script type="text/javascript" src="js/jquery.markup_first_last.js" charset="utf-8"></script>
* <script type="text/javascript">
* //<!CDATA[
* $(document).ready(function(){
* $.firstLast();
* // or
* $('selector').firstLast();
* });
* //]]>
* </script>
*
*/
(function($)
{
jQuery.fn.firstLast = function()
{
jQuery(this).children(':first').addClass('first');
jQuery(this).children(':last').addClass('last');
}
jQuery.extend( {
"firstLast" : function(selector)
{
if (typeof selector == "undefined") {
selector = 'ul,ol';
}
jQuery(selector).each(function()
{
jQuery(this).firstLast();
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment