blob: 0986635a5765bba6300b98ee8e0b13fdccd2ea22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
---
title: HTMLElement.lang
slug: Web/API/HTMLElement/lang
translation_of: Web/API/HTMLElement/lang
---
<div>{{ APIRef("HTML DOM") }}</div>
<p>The <code><strong>HTMLElement.lang</strong></code> property gets or sets the base language of an element's attribute values and text content.</p>
<p>The language code returned by this property is defined in <a class="external" href="http://tools.ietf.org/html/rfc1766">RFC 1766</a>. Common examples include "en" for English, "ja" for Japanese, "es" for Spanish and so on. The default value of this attribute is <code>unknown</code>. Note that this attribute, though valid at the individual element level described here, is most often specified for the root element of the document.</p>
<p>This also only works with the <code>lang</code> attribute and not with <code>xml:lang</code>.</p>
<h2 id="Syntax" name="Syntax">Sintaxe</h2>
<pre class="syntaxbox">var <var>languageUsed</var> = elementNodeReference.lang; // Get the value of lang
elementNodeReference.lang = <var>NewLanguage</var>; // Set new value for lang
</pre>
<p><var>languageUsed é uma variável string que obtém o idioma no qual o texto do elemento atual é gravado. NewLanguage é uma variável string cujo valor define o idioma no qual o texto do elemento atual é gravado.</var></p>
<h2 id="Example" name="Example">Exemplo</h2>
<pre class="brush: js">// this snippet compares the base language and
// redirects to another url based on language
if (document.documentElement.lang === "en") {
window.location.href = "Some_document.html.en";
} else if (document.documentElement.lang === "ru") {
window.location.href = "Some_document.html.ru";
}</pre>
<h2 id="Specification" name="Specification">Especificação</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Especificação</th>
<th scope="col">Status</th>
<th scope="col">Comentário</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('DOM2 HTML', 'html.html#ID-59132807', 'lang')}}</td>
<td>{{Spec2('DOM2 HTML')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<p> </p>
|