Ticket #4509 (closed bug: invalid)
jQuery removing slash from self-closing tag
| Reported by: | Vic D'Elfant | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | unfiled | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
By accident, I found out that jQuery appears to be removing the closing slash from a self-closing XHTML tag when inserting this tag through .append(), .prepend() and other ways, which results in invalid XHTML which - on its turn - results in mangled markup.
The following code, for example:
$('body').append('<input type="hidden" name="test" value="test" />');
Results in the following:
<input name="test" value="test" type="hidden">
Whilst the expected output is:
<input name="test" value="test" type="hidden" />
Please see the attached file for a working POC.
Attachments
Change History
Changed 4 years ago by Vic D'Elfant
-
attachment
jquery-bug-poc.htm
added
comment:1 Changed 4 years ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
Since this seems to work fine in Firefox3, I am going to assume you saw this in IE. Internet Explorer does not understand XHTML so it is treating your markup as HTML and trying to fix the invalid markup in the parser.
http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx
If it's happening on other browsers that do support XHTML, be sure that you're serving the page as application/xml+xhtml.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Proof of Concept