You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What specific section or headline is this issue about?
Inheritance
What information was incorrect, unhelpful, or incomplete?
... or I didn't understand.
It reads: "If an element has no lang attribute, it will inherit the lang value set on its parent node, which in turn may inherit it from its parent, and so on."
It's not happening, at least the way I expect it to.
Descendants of an element with lang return a null lang property.
I understand that #text nodes have no lang, and this seems to cut the inheritance chain.
So I tried Element.closest('[lang]') and it also failed.
My nodes descend from a fragment, created from a page with lang at its . The fragment didn't come out with the page's lang, so I added it.
The descendants of the fragment don't seem to inherit its lang even after I brute-forced it.
StackOverflow has a number of developers wandering like zombies searching for the light.
I (one of those zombies) finally wrote a function to walk the hierarchy to do what I believed that closest() should do.
This is Chrome version 132.0.6834.83 (Official Build) (64-bit) in Ubuntu 22.04.5 LTS
What did you expect to see?
I expected the descendants elements of one having lang set, to proudly return their ancestor's lang.
Or, at least, closest to get it.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
Select text and press the button
Cannot upload html & js or 7z files :-(
const getNodeLang = ( node ) => {
let lang = node.lang;
while( ! lang && node.parentNode ){
if( node.parentNode ){
node = node.parentNode;
} else {
return null;
}
lang = node.lang;
}
return lang;
}
Thanks, JC.
In my use case I need to know the language of rach word in a text,
including those inside inner tags.
I can handle it with what I already did, but wanted to communicate the
uncertainty looming.
MDN is so good that it surprises me when something is not crystal clear.
Thanks for all!
Juan
MDN URL
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang
What specific section or headline is this issue about?
Inheritance
What information was incorrect, unhelpful, or incomplete?
... or I didn't understand.
It reads: "If an element has no lang attribute, it will inherit the lang value set on its parent node, which in turn may inherit it from its parent, and so on."
It's not happening, at least the way I expect it to.
Descendants of an element with lang return a null lang property.
I understand that #text nodes have no lang, and this seems to cut the inheritance chain.
So I tried Element.closest('[lang]') and it also failed.
My nodes descend from a fragment, created from a page with lang at its . The fragment didn't come out with the page's lang, so I added it.
The descendants of the fragment don't seem to inherit its lang even after I brute-forced it.
StackOverflow has a number of developers wandering like zombies searching for the light.
I (one of those zombies) finally wrote a function to walk the hierarchy to do what I believed that closest() should do.
This is Chrome version 132.0.6834.83 (Official Build) (64-bit) in Ubuntu 22.04.5 LTS
What did you expect to see?
I expected the descendants elements of one having lang set, to proudly return their ancestor's lang.
Or, at least, closest to get it.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
Select text and press the button
Cannot upload html & js or 7z files :-(
MDN metadata
Page report details
en-us/web/html/global_attributes/lang
The text was updated successfully, but these errors were encountered: