On Sat, May 30, 2009 at 3:32 PM, Karl Swedberg <[email protected]> wrote:
> If I recall correctly, getAttribute/setAttribute("class") doesn't work in
> (at least) IE 6 and 7.
I think you're right. I don't have any browsers setup for testing
right now, so I can't try things out. But, here are two alternatives
that may or may not be better:
This first technique relies on "namespaceURI" being part of the DOM interface:
svgNS = 'http://www.w3.org/2000/svg';
jQuery.className.get = function( elem ) {
if (elem.namespaceURI == svgNS) {
return elem.className.baseVal; // SVG DOM
} else {
return elem.className; // HTML DOM
}
}
jQuery.className.set = function( elem, value ) {
if (elem.namespaceURI == svgNS) {
return elem.className.baseVal = value; // SVG DOM
} else {
return elem.className = value; // HTML DOM
}
}
This second technique relies upon elem.className.baseVal being
"undefined" (and not generating an error or something):
jQuery.className.get = function( elem ) {
if (elem.className.baseVal == undefined) {
return elem.className; // HTML DOM
} else {
return elem.className.baseVal; // SVG DOM
}
}
jQuery.className.set = function( elem, value ) {
if (elem.className.baseVal == undefined) {
return elem.className = value; // HTML DOM
} else {
return elem.className.baseVal = value; // SVG DOM
}
}
-David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---