Skip to content

Instantly share code, notes, and snippets.

@gregoriopellegrino
Last active August 14, 2019 00:03
Show Gist options
  • Save gregoriopellegrino/c94c46933d660a3db233e7a1c9c6f5e6 to your computer and use it in GitHub Desktop.
Save gregoriopellegrino/c94c46933d660a3db233e7a1c9c6f5e6 to your computer and use it in GitHub Desktop.
Very simple script in jQuery to find all the languages present in an HTML document. Useful for controlling the accessibility of documents. Improvements are welcome. #a11y Made to run from the browser development console
// main lang
if ($("html").get(0).hasAttribute("lang")) {
var main_lang = $("html").attr("lang");
} else {
var main_lang = $("body").attr("lang");
}
console.log("Main language is "+main_lang);
// children lang
var langs = [];
$("*[lang]").each(function() {
var lang = $(this).attr("lang");
if ($.inArray(lang, langs) == -1) {
langs.push(lang)
}
});
console.log("Other languages found: "+langs);
@JayPanoz
Copy link

I’ve just pushed an invite – started working on completing this a little bit in a private repo – so it’s fair to enable access for you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment