There is a current check in .attr() for isXMLDoc, but we need a fix that works for foreign elements in HTML documents, meaning the fix needed here cannot be based on the type of document the element is from or in, but based on whether the element is from a namespace other than HTML. Patches (including tests):
This fixes .attr() by not using the DOM HTML method of getting and setting attributes if the element is detected to be foreign. In this case, it falls back to DOM Core's .getAttribute() and .setAttribute(). Tests included.
This adds a new function, isForeignElement. This is similar to isXML (isXMLDoc in jQuery), except that it's based on the namespace of the element itself, rather than the type of document it's in/from, or the way it's parsed (text/html vs. application/xhtml+xml). In the case of IE, we'll get nothing from .namespaceURI, but IE doesn't support foreign elements anyway. So in this case we fall back to using isXML. This means the function isn't defined as detecting whether an element is foreign to the document it's in, but whether the element is foreign to the HTML namespace. See tests in above commit.