You would need to hold onto the original response to do this...

$("#hiddendiv").html(data);
$("#div").text(data);

Then you could get it back out...

var html = $("#hiddendiv").html();

Update based on comment...

You can remove that element before you display it...

var html = $(data);
$('#cookiediv', html).hide();
$('#div').html(html);

Where the cookie message has id="cookiediv" - you may need to adjust the selector to get to this div, but it is almost certainly possible to grab it.

Answer from Fenton on Stack Overflow
🌐
jQuery
api.jquery.com › jQuery.parseHTML
jQuery.parseHTML() | jQuery API Documentation
jQuery.parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace). To prevent trailing/leading whitespace from being converted to text nodes you can pass the HTML string through jQuery.trim.
🌐
jQuery
api.jquery.com › html
.html() | jQuery API Documentation
If you are keeping references to these DOM elements and need them to be unchanged, use .empty().html( string ) instead of .html(string) so that the elements are removed from the document before the new string is assigned to the element.
🌐
marcalbert
marcalbert.wordpress.com › 2015 › 06 › 23 › how-to-convert-a-javascript-string-to-an-html-object-using-jquery
How to convert a javascript string into a html object using jQuery | marcalbert
June 23, 2015 - Javascript: var stringTag = ' '; var htmlObject = $(stringTag); And we could take this object and use it as an object. Reference link: http://stackoverflow.com/questions/2522422/converting-a-javascript-string-to-a-html-object
🌐
GeeksforGeeks
geeksforgeeks.org › jquery-parsehtml-method
JQuery | parseHTML() method | GeeksforGeeks
April 27, 2020 - This parseHTML() Method in jQuery is used to parses a string into an array of DOM nodes. ... Parameters: The parseXML() method accepts three parameter that is mentioned above and described below: data: This parameter is the HTML string to be parsed.
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript string to html
How to Convert String to HTML in JavaScript | Delft Stack
February 2, 2024 - The $(str) syntax creates a jQuery object from the provided string, which can then be used to perform various jQuery operations on the HTML elements.
🌐
Coderwall
coderwall.com › p › jt7ysq › encode-string-to-html-entities-via-jquery
Encode string to HTML entities via jQuery (Example)
October 10, 2022 - fatal: refusing to merge unrelated histories · #html · #javascript · #htmlentities · #jquery · Say Thanks · Respond · 297.5K · 7 · 247.7K · 12 · 147.2K · 1 · nyao · you may also want to check alternatives and their comparison here: http://jsperf.com/htmlencoderegex/25 ·
🌐
Career Karma
careerkarma.com › blog › javascript › how to use the jquery html() method
How to Use the jQuery html() Method | Career Karma
January 12, 2021 - The selector may be as broad as a <p> tag or as specific as a <div> with an id (<div id=‘main-app’></div>). Once the desired element is selected, we can call html() and pass in an HTML string as a parameter to html().
🌐
CodeProject
codeproject.com › Questions › 1036792 › Converting-HTML-element-to-string-in-JavaScript-JQ
Converting HTML element to string in JavaScript / JQuery
November 6, 2015 - Disclaimer: References to any specific company, product or services on this Site are not controlled by GoDaddy.com LLC and do not constitute or imply its association with or endorsement of third party advertisers.