Side navigation
#7673 closed bug (fixed)
Opened December 01, 2010 10:48AM UTC
Closed December 06, 2010 09:59PM UTC
Last modified January 14, 2011 10:20PM UTC
hasClass, removeClass don't work in IE if attribute contains \\r character
Reported by: | sever | Owned by: | jitter |
---|---|---|---|
Priority: | low | Milestone: | 1.5 |
Component: | attributes | Version: | 1.4.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
hasClass, removeClass methods don't work in IE (ver. 7 & 8) if class attribute contains \\r character.
I have modified regular expression used in hasClass function: /[\\n\\t]/g => /[\\r\\n\\t]/g
After this change hasClass, removeClass, removeAttr methods works fine.
Attachments (0)
Change History (11)
Changed December 01, 2010 11:24AM UTC by comment:1
owner: | → sever |
---|---|
status: | new → pending |
Changed December 01, 2010 03:15PM UTC by comment:2
I'm curious to know what the use case is for having a carriage return in your class attribute.
Changed December 01, 2010 05:40PM UTC by comment:3
Replying to [comment:2 rwaldron]:
I'm curious to know what the use case is for having a carriage return in your class attribute.
I have html code formed by XSLT. For example:
<td>
<xsl:attribute name="class">
class1 class2 class3
</xsl:attribute>
</td>
in html we will see:
<td class="
class1 class2 class3
">
</td>
Changed December 01, 2010 06:08PM UTC by comment:4
resolution: | → invalid |
---|---|
status: | pending → closed |
This is not a bug in jQuery. You can EASILY trim that whitespace with jQuery.trim()
Changed December 01, 2010 09:44PM UTC by comment:5
component: | unfiled → attributes |
---|---|
milestone: | 1.next → 1.4.5 |
priority: | undecided → high |
resolution: | invalid |
status: | closed → reopened |
This may be an edge case and could be avoided in the first case but I think this bug is valid. The specs say browser should ignore carriage return characters in the className property (which they do) but jQuery doesn't and thus creates a inconsistency.
Changed December 01, 2010 09:45PM UTC by comment:6
owner: | sever → jitter |
---|---|
priority: | high → low |
status: | reopened → assigned |
Changed December 02, 2010 02:26AM UTC by comment:7
No debate would be complete without a reference to a spec:
This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters. -- http://www.w3.org/TR/html401/struct/global.html#h-7.5.2
White space (spaces, newlines, tabs, and comments) may appear before or after each section. -- http://www.w3.org/TR/html401/struct/global.html#h-7.1
The \\r
isn't mentioned but since \\n
and \\r
often go together it seems reasonable to accept both.
Changed December 02, 2010 07:16AM UTC by comment:8
Replying to [comment:7 dmethvin]:
The\\r
isn't mentioned but since\\n
and\\r
often go together it seems reasonable to accept both.
In my case '\\r' appears right after the last class name: 'class1 class2\\r'.
Changed December 02, 2010 04:37PM UTC by comment:9
Replying to [comment:7 dmethvin]:
The\\r
isn't mentioned but since\\n
and\\r
often go together it seems reasonable to accept both.
The class
attribute if defined as cdata-list
and the specs for cdata (http://www.w3.org/TR/html401/types.html#type-cdata) say
- Ignore line feeds
Changed December 06, 2010 09:59PM UTC by comment:10
resolution: | → fixed |
---|---|
status: | assigned → closed |
Landed both the Sizzle and jQuery pulls.
Changed January 14, 2011 10:20PM UTC by comment:11
milestone: | 1.4.5 → 1.5 |
---|
Move fixed tickets to appropriate milestone
Thanks for taking the time to contribute to the jQuery project by filing a ticket. We require that all bugs include a test case on jsFiddle (http://jsfiddle.net) that clearly demonstrates the issue. If you could please provide such a test case and link it here, we can proceed and investigate this issue.
If you would like to provide a patch, please do so via Github. Thanks again.