aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/document/getelementsbyname/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ru/web/api/document/getelementsbyname/index.html')
-rw-r--r--files/ru/web/api/document/getelementsbyname/index.html90
1 files changed, 90 insertions, 0 deletions
diff --git a/files/ru/web/api/document/getelementsbyname/index.html b/files/ru/web/api/document/getelementsbyname/index.html
new file mode 100644
index 0000000000..73b8921d61
--- /dev/null
+++ b/files/ru/web/api/document/getelementsbyname/index.html
@@ -0,0 +1,90 @@
+---
+title: Document.getElementsByName()
+slug: Web/API/Document/getElementsByName
+translation_of: Web/API/Document/getElementsByName
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p><span class="seoSummary">Метод <strong><code>getElementsByName()</code></strong>  объекта {{domxref("Document")}} возвращает коллекцию {{domxref("NodeList")}} элементов с заданным  {{domxref("element.name","name")}}.</span></p>
+
+<h2 id="Синтаксис">Синтаксис</h2>
+
+<pre class="syntaxbox">var <var>elements</var> = document.getElementsByName(<var>name</var>);
+</pre>
+
+<ul>
+ <li><var>elements</var> — это живая {{domxref("NodeList")}} коллекция. То есть,  она автоматически обновляется, когда элементы с таким же <code>name</code> добавляются/удаляются из документа.</li>
+ <li><var>name </var>— это значение поля  <code>name</code> элемента(элементов).</li>
+</ul>
+
+<h2 id="Пример">Пример</h2>
+
+<pre class="brush:html">&lt;!DOCTYPE html&gt;
+&lt;html lang="en"&gt;
+&lt;title&gt;Example: using document.getElementsByName&lt;/title&gt;
+
+&lt;input type="hidden" name="up"&gt;
+&lt;input type="hidden" name="down"&gt;
+
+&lt;script&gt;
+ var up_names = document.getElementsByName("up");
+ console.log(up_names[0].tagName); // displays "INPUT"
+&lt;/script&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="Notes">Notes</h2>
+
+<p>The {{domxref("element.name","name")}} attribute can only be applied in (X)HTML documents.</p>
+
+<p>The returned {{domxref("NodeList")}} Collection contains <em>all</em> elements with the given <code>name</code>, such as {{htmlelement("meta")}}, {{htmlelement("object")}}, and even elements which do not support the <code>name</code> attribute at all.</p>
+
+<div class="warning">
+<p>The <strong>getElementsByName</strong> method works differently in IE10 and below. There, <code>getElementsByName()</code> also returns elements that have an <a href="/en-US/docs/Web/HTML/Global_attributes/id"><code>id</code> attribute</a> with the specified value. Be careful not to use the same string as both a <code>name</code> and an <code>id</code>.</p>
+</div>
+
+<div class="warning">
+<p>The <strong>getElementsByName</strong> method works differently in IE. There, <code>getElementsByName()</code> does not return all elements which may not have a <code>name</code> attribute (such as <code>&lt;span&gt;</code>).</p>
+</div>
+
+<div class="warning">
+<p>Both IE and Edge return an {{domxref("HTMLCollection")}}, not a {{domxref("NodeList")}}</p>
+</div>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', '#dom-document-getelementsbyname', "Document.getElementsByName()")}}</td>
+ <td>{{ Spec2('HTML WHATWG') }}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName("DOM2 HTML", "html.html#ID-71555259", "Document.getElementsByName()")}}</td>
+ <td>{{Spec2("DOM2 HTML")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.Document.getElementsByName")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("document.getElementById()")}} to return a reference to an element by its unique <code>id</code></li>
+ <li>{{domxref("document.getElementsByTagName()")}} to return references to elements with the same <a href="/en-US/docs/Web/API/Element/tagName">tag name</a></li>
+ <li>{{domxref("document.querySelector()")}} to return references to elements via CSS selectors like <code>'div.myclass'</code></li>
+</ul>