views:

87

answers:

2

Doing a german site, and have a JS alert to say you havn't completed all the required fields.

So want to get the langage of the HTMLpage

Here's the HTML;

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

This is my JS.... it seems to error and not alert at all with the lang bits...

How do it get the xml:lang attribute?

var lang = document.getElementByTagname("html").attributes.getNamedItem("xml:lang").value;
                alert("You must complete all the required information");
                alert(lang);
+2  A: 

This works:

document.getElementsByTagName('html')[0].getAttribute('xml:lang');
Douwe Maan
+2  A: 

Since you have an xml:lang attribute and not a lang attribute, you aren't writing HTML Compatible XHTML, therefore:

var htmls = document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'html');
var html = htmls[0];
var lang = html.getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');.

(OK, this is slightly tongue in cheek. You should probably fix your markup to conform to the compatibility guidelines instead. Then just

document.getElementsByTagName('html')[0].lang

)

David Dorward
Yeh cheers, completly missed it... @lang is now in there. I feel school boy. lol
Will Hancock