$(markup)
parses as HTML, not XML, giving you an HTMLUnknownElement
with tagName example
. dir
is an existing HTML attribute which may only have the values rtl
or ltr
. Anything else is ignored, which is why the custom attribute isn't readable under the DOM property dir
.
(Contrary to what you might expect from the name, jQuery's attr()
method actually usually represents DOM property access and not HTML attribute access, even though it allows the HTML attribute names to be used as aliases.)
You may have further problems in IE which doesn't much like custom elements being dropped into HTML.
Getting a browser to parse XML isn't quite as simple as you might think. Having an XML document returned by XMLHttpRequest
(ajax()
) works everywhere, so if you can, move the XML into an AJAX response.
Otherwise, getting an XML parser to read a string isn't the same on all browsers (and older browsers can't do it at all). On IE you have to use a new ActiveXObject('Microsoft.XMLDOM')
; on other browsers you often get a new DOMParser()
; failing that, you can try to document.implementation.createDocument().loadXML()
.