I want to do the following.
$("a").click(function (event) {
event.preventDefault();
$.get($(this).attr("href"), function(data) {
$("html").html(data);
});
});
I want the behavior of all hyperlinks to make a ajax calls and retrieve the html.
Unfortunately you cannot simply replace the current html with the html you receive in the ajax response.
How can grab only what is within the <body> </body> tags of the ajax response so that i can replace only the contents of the body in the existing html.
Edit: the <body> opening tag will not always be just <body> it may sometimes have a class e.g.
<body class="class1 class2">
If I understand you correctly, grab the content between the body tags with a regex.
EDIT
Based on your comments below, here’s an update to match any body tag, irrespective of its attributes:
The regex is:
Add the ‘i’ switch to match upper and lowercase.
And please ignore my comment regarding the ‘s’ switch, in JavaScript all RegExp are already single-line by default, to match a multiline pattern, you add ‘m’. (Damn you Perl, interfering with me when I’m writing about JavaScript! 🙂