Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 869
ashurexm Avatar asked Aug 20 '10 01:08

ashurexm


2 Answers

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.

like image 128
Nick Craver Avatar answered Oct 27 '22 15:10

Nick Craver


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.

like image 33
hatkirby Avatar answered Oct 27 '22 15:10

hatkirby