Skip to main content

Bug Tracker

Side navigation

#13056 closed bug (patchwelcome)

Opened December 14, 2012 11:12AM UTC

Closed December 21, 2012 03:25PM UTC

Last modified July 25, 2013 02:20PM UTC

Bug on accessing class name in addClass and Remove class?

Reported by: Michael van Engelshoven <> Owned by: Michael van Engelshoven <>
Priority: low Milestone: None
Component: attributes Version: 1.8.3
Keywords: Cc:
Blocked by: Blocking:


While debugging the jquery-svg plugin from keith wood I found a difference how you hande class names in methods like addClass() or removeClass() and the class filter in the sizzle engine. In jquery core always elem.className is used while sizzle uses elem.getAttribute('class') if the className attribute doesn't exist. Maybe this is a bug?!


Attachments (0)
Change History (8)

Changed December 14, 2012 02:07PM UTC by dmethvin comment:1

owner: → Michael van Engelshoven <>
status: newpending

Do you have an example of a bug related to that? Please provide an example at or so we can see what's up.

Changed December 17, 2012 12:08PM UTC by Michael van Engelshoven <> comment:2

status: pendingnew

I wasn't sure if this is a bug, but I created a few tests which fail in firefox:

The specification for Document Object Model HTML sais, className is only available for html documents. For xml we have to use getAttribute() and setAttrbute().

Changed December 21, 2012 04:03AM UTC by dmethvin comment:3

resolution: → wontfix
status: newclosed

SVG documents are not DOM documents, we don't support them for many operations. We don't list them all in the docs because, SVG is on the wonfix list--it's just out of scope for jQuery.

Changed December 21, 2012 07:34AM UTC by anonymous comment:4

As you can see in my jsbin example, this is not a svg problem. The example is based on code from the jquery documentation… I just found this problem by fixing the svg plugin.

By the way: What makes you think that SVG is not a DOM document? Its a simple xml document, too.

Changed December 21, 2012 03:23PM UTC by dmethvin comment:5

resolution: wontfix
status: closedreopened

It's an XML document. That's why you used $.parseXML() to parse it. jQuery is primarily intended for use with HTML documents. Documents that are XML but not HTML often have different semantics and lack various interfaces. The class attribute is not special in any way in that XML document, it could have been named kind.

The basic traversing, selecting, and manipulating works with XML but it is not jQuery's design goal to support peculiars of XML dialects like SVG, VML, etc. or to give generic XML the same interfaces as an HTML DOM.

Fortunately you have .attr() and can set whatever attributes you'd like on the XML.

Changed December 21, 2012 03:25PM UTC by dmethvin comment:6

component: unfiledattributes
priority: undecidedlow
resolution: → patchwelcome
status: reopenedclosed

If someone would like to make a patch to use .getAttribute("class") instead of .class it should include a jsperf. Be mindful of the size as well, it is probably better to use .getAttribute() everywhere rather than branch the code.

Changed December 28, 2012 04:59PM UTC by timmywil comment:7

It's worth pointing out that add/removeClass has never worked as XML and it's been ok.

Changed July 25, 2013 02:20PM UTC by dmethvin comment:8

#14183 is a duplicate of this ticket.