Last active
December 27, 2015 12:19
-
-
Save hcosta/7324561 to your computer and use it in GitHub Desktop.
Clone all html elements in a div with all form values dinamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Requires jQuery*/ | |
function clone(from, to){ | |
// Do this before clone | |
$('[type=text], textarea').each(function(){ this.defaultValue = this.value; }); | |
$('[type=checkbox], [type=radio]').each(function(){ this.defaultChecked = this.checked; }); | |
$('select option').each(function(){ this.defaultSelected = this.selected; }); | |
// Then clone | |
var html_content = $(from).html(); | |
$(to).html(html_content); | |
} | |
/* Usage */ | |
clone("div#source", "div#target"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment