tl; dr summary : jQuery load()method is called like:
$('#foo').load('similar.html #foo')
leads to a DOM structure:
<div id="foo">
<div id="foo">β¦</div>
</div>
What is the right way to swap part of a page with an equivalent part on a similar page using jQuery that doesn't double the wrapper?
I want to create a website that:
- Contains a permanent "chrome" site around all pages (heading, navigation bar, search box, etc.).
- Collapses the "content" of the site during navigation (all chrome is permanent).
- Provides the ability to view the history and bookmarks of standard viewing.

- # 3, , , ( ).
, , :
<html><head><title>NAME</title>β¦</head><body>
<div id="chrome">β¦</div>
<div id="content">β¦</div>
</body></html>
jQuery, AJAX . history.pushState(), :
$('#nav a').click(function(e){
var url = this.href;
$('#content').load(url+" #content",function(html){
var title = /<title>(.+?)<\/title>/i.exec(html)[1];
history.pushState({},title,url);
$('title').html(title);
});
e.preventDefault();
});
; .
, , DOM :
<div id="content">
<div id="content">contents from other page</div>
</div>
id, ...
<div id="content-wrap"><div id="content">β¦</div></div>
JS -...
$('#content-wrap').load(url+" #content",β¦);