Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may try this js code.</p> <p>Scenario:-I was having the scenario of making clone of table inside a div and also removing the clone on click of remove clone link.</p> <pre><code> &lt;script&gt; var count=1; function makeClone() { var $clone = $(".cloneTable:first").clone(true); $clone.find(':text,:file').each(function() { $(this).attr('id',($(this).attr("id")+count)); $(this).val(' '); }); $clone.find("a").each(function() { $(this).val('').attr('id', function(_, id) { return count; }); }); $clone.find("span").each(function() { $(this).attr({ id: $(this).attr("id") + count }); }); $clone.attr( 'id', function() { return this.id + count; }); //for use of datepicker $clone.find('.myDate').removeClass('hasDatepicker').datepicker(); $clone.appendTo('#addCarrierDiv'); $('#Test'+count).html('&lt;strong&gt;Test '+(parseInt(count)+parseInt(1))+'&lt;/strong&gt;'); count=count+1; } &lt;/script&gt; </code></pre> <p>Here i am updating my answer for providing the code to remove a clone.</p> <pre><code>$(document).ready(function(){ $('.removeClone').live('click',function() { var length=$('.cloneTable').length; if(length==1) { alert('There should be atleast one clone'); return false; } var id = $(this).attr('id'); var countVal=parseInt(id)+parseInt(1); $(this).closest('.cloneTable').remove(); for(var removecount=parseInt(countVal);removecount&lt;=length;removecount++) { $clone=jQuery("#maintable"+removecount); if(removecount==1) { $clone.find(':text,:file').each(function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); $(this).attr('id',testVal); }); $clone.find("a").each(function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); $(this).attr('id',testVal+id); }); $clone.find("span").each(function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); $(this).attr({ id: testVal }); $(this).html('&lt;strong&gt;Test '+removecount+'&lt;/strong&gt;'); }); $clone.attr( 'id', function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); return (testVal); }); id=parseInt(id)+parseInt(1); } else { $clone.find(':text,:file').each(function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); $(this).attr('id',testVal+id); }); $clone.find("a").each(function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); $(this).attr('id',testVal+id); }); $clone.find("span").each(function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); $(this).attr({ id: testVal+id }); $(this).html('&lt;strong&gt;Test '+removecount+'&lt;/strong&gt;'); }); $clone.attr( 'id', function() { var textId=$(this).attr("id"); var testVal=textId.replace(/[0-9]/g, ''); return (testVal+id); }); id=parseInt(id)+parseInt(1); } } count=parseInt(count)-parseInt(1); }); }); </code></pre> <p>This work's fine for me.Hope this code may help you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload