Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

jQuery .clone() method

0 votes
3 views
added Mar 29 in jQuery by Callum Corporal (1,350 points)
edited Apr 2 by LC Marshal

Clone e and insertafter it

$(document).ready(function() {
  var e = $('#project');
  for (var i = 0; i < 8; i++) {
    e.clone().insertAfter(e);
  }
});

4 examples

0 votes
responded Mar 29 by Callum Corporal (1,350 points)
var clone = $('#clone').clone();
var increment=0;
$('.addprop').live('click', function() {
    $(clone).clone().addClass('add-margin').attr("name","some-name"+increment).removeAttr('id').insertAfter(".addprop");
    increment++;
});
0 votes
responded Mar 29 by Callum Corporal (1,350 points)
edited Mar 30 by LC Marshal

clone the address  and append it as a new address

var newaddress= $("#addresses div.address").eq(0).clone();
newaddress.find('input').each(function() {
    this.name= this.name.replace('[0]', '['+i+']');
});
$('#addresses').append(newaddress);
0 votes
responded Mar 29 by Callum Corporal (1,350 points)
edited Mar 30 by LC Marshal

To clone specific selector

if ($("body").hasClass('page-project-outlook')) { 
   $('.page-header').html($("ol.breadcrumb li:last-child" ).html());  
}
0 votes
responded Apr 5 by LC Marshal Second Warrant Officer (6,690 points)

if the expiry message is exist on the body, clone the element to another element.

$(function() {
  var expiry = $('span.expiry_msg');  
  if ($(expiry).length) { 
   $(expiry).clone().appendTo('#get-expired-msg').addClass('expiry-on-header').fadeIn(500);
  }
});
lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...