views:

41

answers:

1

My CMS is adding extra HTML markup after the closing HTML tag. I would like remove it using jQuery and am unable to find a selector that can select the closing HTML tag.

Here is example markup:

<html>
  <head> [...] </head>
  <body> [...] </body>
</html>
<span></span><span></span><span></span><div></div><div></div>

Here is my feeble attempt:

$('html:last').nextAll().remove()
$('</html>').nextAll().remove()

Ideally, I would like to figure out where its coming from, but for now, just strip it off..

+4  A: 

You can't use on jQuery to reliably do this...invalid HTML will have somewhat unpredictable behavior with the DOM (which is what jQuery's working through). This needs to be solved server-side.

Nick Craver
Right. I guess I wasn't clear. This is simply a temporary fix until the source of the extra mark up can be found. Now, are you saying that this can't be done via jQuery?
Kobe
+1 Treat the cause, not the symptoms.
BoltClock
@Kobe - It can't be reliably done with jQuery...yes. As Nick said, don't waste time creating a temporary fix because they become permanent fixes. Fix the issue server-side.
JasCav