How to obtain lang attribute in HTML using JavaScript?

后端 未结 2 1776
甜味超标
甜味超标 2020-12-08 18:29

How to obtain lang attribute in HTML using JavaScript?




        
相关标签:
2条回答
  • 2020-12-08 18:41

    Just.

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

    And with the namespace

    document.getElementsByTagName('html')[0].getAttribute('xml:lang');
    
    0 讨论(0)
  • 2020-12-08 18:46

    If both attributes agree on their values (as they should), it's enough to read either of them. I'd suggest using

    document.documentElement.lang
    
    0 讨论(0)
提交回复
热议问题