Reputation: 33
I need to clone a section of markup that has already been modified in the DOM. I want to get the original HTML source - what is seen in View > Source.
clone() uses what's in the DOM
Upvotes: 3
Views: 1811
Reputation: 1268
I have written a library for this task some time ago :)
http://www.moyablog.com/innerouter-xhtml/
originalOuterXHTML(element)
will accomplish what you want
Upvotes: 0
Reputation: 4440
Try putting it in a variable
before the DOM is manipulated. I use this method for jQuery templating... var template = $('#template').html()
Upvotes: 2
Reputation: 7183
you would need to copy that HTML into something before the changes are made to the DOM. what the DOM currently has at any given point in time is what you have access to, not past/future versions unless you explicitly saved them to something
Upvotes: 0
Reputation: 78920
A straightforward approach would be to preserve the original markup in a hidden div
. Then, clone that hidden content.
Another option would be to do an AJAX request to retrieve the original document, then load the HTML you want to duplicate from there.
Upvotes: 1
Reputation: 318798
You can't.
If you need it, store the original markup in a JavaScript var before making any modifications.
Upvotes: 7