My design of a page forces me to refresh the whole page with html that I have loaded via ajax.
$('html').replaceWith(data);
Gives me errors. Any ideas?
The * selector selects all elements in the document, including html, head and body. If the * selector is used together with another element, it selects all child elements within the specified element. Tip: The * selector can be heavy to process for some browsers.
We can replace HTML elements using the jQuery . replaceWith() method. With the jQuery replaceWith() method, we can replace each element in the set of matched elements with the provided new content and return the set of elements that were removed.
To replace a DOM element with the specified HTML or DOM elements using jQuery, use the replaceWith() method. The replaceWith (content) method replaces all matched elements with the specified HTML or DOM elements. This returns the JQuery element that was just replaced, which has been removed from the DOM.
I had the same issue, but this didn't help.
If you need to also replace the <head>
tag (so, the whole page), you can also do
document.write(newPage);
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