(function($){ $.fn.wrapMatch = function(count, className) { var length = this.length; for(var i = 0; i '); } return this; }; })(jQuery); $('.list-parent li').wrapMatch(5,'newclass');