html - JavaScript gets rid of trailing slash in <img > tag - Stack Overflow

I have the following JS code:validateConfigName.html('<img src="rtaimagescheck-24.png&q

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?

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?

Share Improve this question asked Aug 20, 2010 at 1:27 ashurexmashurexm 6,3354 gold badges48 silver badges71 bronze badges 2
  • 4 @Thilo - It doesn't...but if I'm hiring a programmer, I'm after the one that does ask why. I wish more people actually cared why something is like it is. – Nick Craver Commented Aug 20, 2010 at 2:30
  • 2 @Thilo - Nick is right, it doesn't. Just interested in why I was seeing the discrepancy. I already know that it's not a big deal, but was wondering if anyone with some deeper insight could definitively answer the question. What is SO good for if you can't ask the simple question of why? – ashurexm Commented Aug 20, 2010 at 15:54
Add a ment  | 

4 Answers 4

Reset to default 6

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.

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.

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.

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

Nothing to worry about though..

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744168464a4561416.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信