Last active
August 14, 2019 00:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :-)