Skip to content

Instantly share code, notes, and snippets.

@IAMIronmanSam
Last active March 16, 2016 16:51
Show Gist options
  • Select an option

  • Save IAMIronmanSam/1e72ac7d90290189def3 to your computer and use it in GitHub Desktop.

Select an option

Save IAMIronmanSam/1e72ac7d90290189def3 to your computer and use it in GitHub Desktop.
Clone Div
// Do this on $(document).ready(function() { ... })
var divClone = $("#some_div").clone();
// Change the content temporarily
$("#some_div").html("Yeah all good mate!");
// Use this command if you want to keep divClone as a copy of "#some_div"
// Restore element with a copy of divClone
$("#some_div").replaceWith(divClone.clone());
// Any changes to "#some_div" after this point will affect the value of divClone
// Restore element with divClone itself
$("#some_div").replaceWith(divClone);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment