When you assign JavaScript code to the onclick handler, it runs in a special area where the properties of this element are directly accessible, since they execute inside the with (element) { } block.
In your example, the lang variable corresponds to the lang attribute of the element. Other examples that lead to the same error include id , title , style and href . Think about it by running the following code:
function lang() { } with(element) { lang("en-US");
You can simply specify your function:
var MyFancyFunctions { lang: function { } };
<a onclick="MyFancyFunctions.lang('en-US')">English</a>
Or just remove the ambiguity:
<a onclick="window.lang('en-US')">English</a>
Literature:
internal raw handler
source share