I need to be capable to restore the HTML code inside a div as it was at page ready. I need this because I want to make some changes to the HTML code after page ready and then revert it to the way it was at page ready when I need it..
I was thinking to use clone, but how do I just copy the content of the div without paste it? I need to copy the content of the div at page ready and then paste it/replace the div with the original when I need..
I am rather new to jquery, I tried several things without luck, I can't find out what I need. Thank you for any suggestion!
To clone an element using jQuery, use the jQuery. clone() method. The clone() method clones matched DOM Elements and select the clones. This is useful for moving copies of the elements to another location in the DOM.
First, select the <ul> with the id menu by using the querySelector() method. Second, create a deep clone of the <ul> element using the cloneNode() method. Third, change the id of the cloned element to avoid duplicate. Finally, append the cloned element to the child nodes of the document.
jQuery html() Method The html() method sets or returns the content (innerHTML) of the selected elements. When this method is used to return content, it returns the content of the FIRST matched element.
jQuery clone() Method The clone() method makes a copy of selected elements, including child nodes, text and attributes.
You can copy it into a variable for later.
var originalContent;
$(document).ready(function() {
originalContent = $('#theDiv').clone();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With