Custom plugin to add/remove grid items ?

To use this plugin JQuery library is required.Include JQuery library.

(function ( $ ) {
$.fn.manageGrid = function( options ) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
parentDiv: "#parentID",
action:"add",
elementObj:""
}, options );

 if(settings.action=='add'){
  myclone=$(this).first().clone();
  myclone.find('input').prop('value','');
  //cloneHtml=$(cloneHtml).find('input').prop('value','');
  myclone.appendTo(settings.parentDiv);
  }else if(settings.action=='remove')
  {
   if($(settings.elementObj).parent().parent().index()==0){
    alert('Can not be Removed!');
   }else{
    if(confirm('Do You Really want to remove this?')==true){
   $(settings.elementObj).parent().parent().remove(); }}
  }
};
}( jQuery ));





How to use this plugin: 

 
    (function ( $ ) {
$.fn.manageGrid = function( options ) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
parentDiv: "#parentID",//replace with your parent div ID
action:"add", //add/remove
remove:"class",//put remove class
removeLinkUrl:"",
elementObj:""
}, options );




Comments