Side navigation
#8218 closed bug (duplicate)
Opened February 09, 2011 08:51AM UTC
Closed February 09, 2011 12:21PM UTC
Last modified February 09, 2011 12:21PM UTC
jQuery#html messes up when quotes are omitted around attribute values
Reported by: | mathias | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | manipulation | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
For example,
$el.html('<a href=http://www.google.com/>foo</a> bar')
This would actually result in the following HTML:
<a href="http://www.google.com"></a>foo bar
Whereas it should be:
<a href="http://www.google.com/">foo</a> bar
Here’s a simple test case: http://jsfiddle.net/mathias/9MgB4/
(Note that omitting these quotes is perfectly valid in HTML — they’re only required if the attribute value contains spaces or other special characters.)
Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!
This is a known problem and you can check the ticket mentioned below for progress on this issue.
Replying to [ticket:8218 mathias]:
The HTML 4.01 specification says about this:
and the XHTML specification says:
So in both HTML and XHTML the html snippet included in your report would be considered invalid. The HTML spec recommends quoting whenever possible and XHTML requires it. Only in HTML5 your snippet would be considered legal.
If the html string passed to
.html()
is under your control you really should be quoting the attribute values or workaround this issue by:/
before the>
(e.g. even an emptyclass=""
will do)/
and>