Anchor hreflang attribute

Definition and Usage

hreflang The attribute sets or returns the language of the link hreflang attribute value.

hreflang The attribute specifies the language of the linked document.

Tip:To view all available language codes, please visit ourLanguage Code Reference Manual.

Example

Example 1

Get the language code of the link:

var x = document.getElementById("myAnchor").hreflang;

Try it yourself

Example 2

Change the language code of the link:

document.getElementById("myAnchor").hreflang = "fr";

Try it yourself

Syntax

Return hreflang attribute:

anchorObject.hreflang

Set hreflang attribute:

anchorObject.hreflang = languagecode

属性值

描述
languagecode 两个字母的语言代码,规定表示链接文档的语言。

技术细节

返回值: 字符串值,表示链接文档的语言。

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持

相关页面

HTML 参考手册:HTML <a> hreflang 属性