Funny, I just had and solved this problem yesterday!
The issue is that even though you specify the XHTML doctype, the DOM (at least in FireFox) will only follow XHTML rules if the Content-Type header is set appropriately, like application/xhtml+xml
. This includes manipulating the DOM with JavaScript, including jQuery. As an experiment, consider the following code:
var foo = $('<div></div>');
foo.html('<img src="#" />');
console.debug(foo.html());
This code will have different results depending on what Content-Type is set. If the Content-Type is text/html
, you'll get back <img src="#">
, because with plain-ole HTML, that is correct. However, if the Content-Type is application/xhtml+xml
, or any of the other acceptable MIME content types for XHTML, you should get back <img src="#" />
.
So, whatever server-side framework you're using, you'll need to add that header to the response. If it's a static file, you should be able to do it with a meta tag:
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
You can check the headers for the page load using the NET tab in FireBug.
I had the additional issue with ASP.NET MVC where it wouldn't set content type, even though I was specifically setting it. The trick is that you need to set it after the call to view. So, this should work:
public void ActionResult Index()
{
var result = this.View();
this.Response.ContentType = "application/xhtml+xml";
return result;
}
EDIT: I just saw your edit and you're setting the wrong Content-Type
with your meta tag. See the rest of my answer for more details.