Recently I was looking for a solution on how to dynamically pre load page content using Ajax. I used to do it all the time with the response as Json or XML but never pure HTML. Making a simple request to a static page, returns to me HTML that I have inject into my content. However, many CMS applications returns HTML content properly formatted. Meaning my loaded content contains also <head> and <body> tags which of course I need to remove.
Here is a simple solution how to do that:
var result = myhtml.split(/<body[^>]*>|<\/body>/gi); if(result.length==3) //body detected myhtml = result;