In the following code want to remove the html and get it in a variable.How to go about this.
<div id="tr1">Server</div>
var t = $("#tr1").remove();
console.log(t); // Should print <div id="tr1">Server</div>
OR should .detach()
be used
To get the element HTML as string, you can use the outerHTML
property of the DOM node:
jQuery:
console.log(t.prop('outerHTML'));
Or using DOM node:
console.log(t[0].outerHTML);
I don't think remove() will return you the HTML code when you delete the element.
To get the html code maybe you should look this answer: https://stackoverflow.com/a/8645992/3133256 (the updated)
Server
` isn't valid HTML markup – A. Wolff May 11 '14 at 15:17