paleozogt
paleozogt

Reputation: 6573

reading namespaced attributes with jquery

Given a document like this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<body>
    ...
</body>

How can I read the xml:lang attribute using jquery? I can query for elements that have xml:lang like this:

$('[xml\\:lang]')

but I don't know how to get the attribute itself. attr('lang') and attr('xml\\:lang') don't work. I've a jsfiddle showing this here.

Upvotes: 4

Views: 390

Answers (1)

Felix Kling
Felix Kling

Reputation: 816960

: has only to be escaped in selectors, since they indicate the start of pseudo selectors. As attribute name you don't have to escape it:

.attr('xml:lang')

works fine.

Upvotes: 2

Related Questions