#13056 closed bug (patchwelcome)
Bug on accessing class name in addClass and Remove class?
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | attributes | Version: | 1.8.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Hey!
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?!
Refernces:
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
Owner: | set to Michael van Engelshoven <[email protected]…> |
---|---|
Status: | new → pending |
comment:2 Changed 10 years ago by
Status: | pending → new |
---|
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
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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
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
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
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
Component: | unfiled → attributes |
---|---|
Priority: | undecided → low |
Resolution: | → patchwelcome |
Status: | reopened → closed |
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
It's worth pointing out that add/removeClass has never worked as XML and it's been ok.
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.