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

jQuery .clone() method

0 votes
52 views
added Mar 29 in jQuery by Callum Sergeant (1,480 points)
edited Jul 12 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);
  }
});

 

7 Responses

0 votes
responded Mar 29 by Callum Sergeant (1,480 points)
edited Jul 12 by LC Marshal
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 Sergeant (1,480 points)
edited Jul 12 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 Sergeant (1,480 points)
edited Jul 12 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 Lieutenant (13,570 points)
edited Jul 12 by LC Marshal
//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);
  }
});
0 votes
responded May 3 by LC Marshal Lieutenant (13,570 points)
edited Jul 12 by LC Marshal
//To clone button into .package class

$(function(){
  var $baby= $('.baby-element').clone();
  $('.mother').html($baby);
});

 

0 votes
responded May 3 by LC Marshal Lieutenant (13,570 points)
edited Jul 12 by LC Marshal
//Clone element 

var catName = $('.forum-category > a'),
    crumbCat = $('ol.breadcrumb li:nth-child(4)'),
    catUrl = $(location).attr('href'),
    urlParts = catUrl.split("/"),
    endUrl = urlParts[urlParts.length-2],
    forumPage = '/property-forum/',
    resultUrl = forumPage + endUrl,
    CrumbCatLast = $(catName).attr('href', resultUrl).clone();
    // alert(endUrl);

$(catName).attr('href', resultUrl);
$(crumbCat).html(CrumbCatLast);

 

0 votes
responded Jun 29 by LC Marshal Lieutenant (13,570 points)
edited Jul 12 by LC Marshal
//Clone #project to be 9 altogether
$(document).ready(function() {
  var e = $('#project');
  for (var i = 0; i < 8; i++) {
    e.clone().insertAfter(e);
  }
});
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...