(function($){ $.HandleNesting = function(el, options){ // To avoid scope issues, use 'base' instead of 'this' // to reference this class from internal events and functions. var base = this; // Access to jQuery and DOM versions of element base.$el = $(el); base.el = el; base.items = []; base.blank = null; // Add a reverse reference to the DOM object base.$el.data("HandleNesting", base); base.init = function(){ base.options = $.extend({},$.HandleNesting.defaultOptions, options); base.items = base.$el.children('li'); if(base.items.length) { base.blank = $(base.items[base.items.length-1]).clone(); } base.addButtons(); }; base.addButtons = function() { base.addAddButton(); base.items.each(function(i,item) { base.addRemoveButton(item); }) }; base.addAddButton = function() { var addButton = $('