views:

73

answers:

4

I have the following JS code:

validateConfigName.html('<img src="/rta/images/check-24.png" />');

But when it executes in Firefox I see this as the generated code:

<img src="/rta/images/check-24.png">

Why?

+1  A: 

In HTML the <img> tag is supposed to be <img>, in XHTML it'll be <img />...so depending on what DOCTYPE your page is using, this will vary.

From the HTML 4.0 Spec for <img>:

Start tag: required, End tag: forbidden

In XHTML elements must be closed:

Well-formedness is a new concept introduced by [XML]. Essentially this means that all elements must either have closing tags or be written in a special form (as described below), and that all the elements must nest properly.

Nick Craver
My doctype looks like:`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">`
manyxcxi
@manyxcxi - How are you viewing the code, firebug, view selection source, other?
Nick Craver
I'm viewing using the Web Developer Toolbar FF add on. I guess I never really stopped to think about it but it makes sense that I'm not viewing exactly what the code was when I view generated code.
manyxcxi
His DOCTYPE doesn't matter. He's not serving the page as XHTML.
Eli Grey
A: 

It's the way, the browser renders your html code according to the doctype used.

Nothing to worry about though..

Starx
+2  A: 

Generated code, as in, like Firebug or something? Firebug operates on the DOM and not actual source code which means that it may not look exactly the same as the code you entered. It shouldn't really make a difference, though.

hatkirby
Using the Web Developer Toolbar add-on in Firefox I did View Generated Source.
manyxcxi
Yeah, that would be the same thing as Firebug. It's just because it's regenerating your source instead of looking at the actual code. Nothing to worry about.
hatkirby
+1  A: 

It's because you're not serving XHTML, even if your DOCTYPE is an XHTML doctype. An XHTML document isn't treated as XHTML unless you either serve it as application/xhtml+xml, application/xml, or text/xml using the Content-Type HTTP header.

Eli Grey
Should I set this at an apache/.htaccess level or through PHP?
manyxcxi