Fatal in CLASS function with XHTML DocumentFragment: "elem.getAttribute is not a function"

Fatal in CLASS function with XHTML DocumentFragment: "elem.getAttribute is not a function"

(This is ticket 6162 which I spammed here after a question on the IRC channel.)


Since jQuery 1.4, my XHTML web-app (too vague, I know) throws a fatal error in the |CLASS| function. Apparently, the |elem| that is being used is not an element but a |DocumentFragment|.

When I switch the |Content-Type| to |text/html|, the problem is gone.

I have hackily patched the |CLASS| function in jquery-1.4.2.js on line 3269 to check for a |firstChild| as follows:

  1. var className = elem.className; if (!className) {

if (elem.getAttribute) {

  • className = elem.getAttribute('class');

  • } else if (elem.firstChild && elem.firstChild.getAttribute) {

  • className = elem.firstChild.getAttribute('class');

  • }

  • } return (" " + className + " ").indexOf( match ) > -1;

  • The patches from ticket #5706 dit not help. Does this bug also fall under "We're going to tackle this, and a number of other XML/XHTML/XUL/SVG related issues post-1.4."