Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select and replace the whole page with jQuery

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?

like image 816
Felix Andersen Avatar asked Apr 27 '09 13:04

Felix Andersen


People also ask

How do you select an entire document in jQuery?

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.

Can we replace in jQuery?

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.

How do you replace an element with another in jQuery?

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.


1 Answers

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);
like image 88
Robin Avatar answered Sep 20 '22 12:09

Robin