JavaScript gets rid of the trailing slash in the <img /> tag

I have the following JS code:

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

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

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

Why?

+4
source share
4 answers

In HTML, the <img> must be <img> , in XHTML it will be <img /> ... so depending on which DOCTYPE your page is using, this will change.

From the HTML 4.0 spec for <img> :

Start tag: required ; End tag: prohibited

In XHTML, elements must be closed:

Good formality is a new concept introduced by [XML]. In essence, this means that all elements must either have closing tags or be written in a special form (as described below), and that all elements must be placed correctly.

+6
source

Generated code, such as Firebug or something else? Firebug works with the DOM, not the source code, which means that it cannot look exactly like the code you entered. However, this should not change.

+2
source

This is because you are not using XHTML, even if your DOCTYPE is an XHTML doctrine. An XHTML document is not considered XHTML unless you serve it as application/xhtml+xml , application/xml or text/xml using the <T23> HTTP header.

+1
source

In this case, the browser displays your html code according to the doctype used.

Nothing to worry though ..

0
source

All Articles