Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13056 closed bug (patchwelcome)

Bug on accessing class name in addClass and Remove class?

Reported by: Michael van Engelshoven <[email protected]…> Owned by: Michael van Engelshoven <[email protected]…>
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?!

https://github.com/jquery/sizzle/blob/1.8.2/sizzle.js#L600 https://github.com/jquery/jquery/blob/1.8.3/src/attributes.js#L57

Change History (8)

comment:1 Changed 10 years ago by dmethvin

Owner: set to Michael van Engelshoven <[email protected]…>
Status: newpending

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

comment:2 Changed 10 years ago by Michael van Engelshoven <[email protected]…>

Status: pendingnew

I wasn't sure if this is a bug, but I created a few tests which fail in firefox: http://jsbin.com/oyisis/1

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

comment:3 Changed 10 years ago by dmethvin

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.

comment:4 Changed 10 years ago by anonymous

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.

comment:5 Changed 10 years ago by dmethvin

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.

comment:6 Changed 10 years ago by dmethvin

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.

comment:7 Changed 10 years ago by timmywil

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

comment:8 Changed 10 years ago by dmethvin

#14183 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.