Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

Summary

name gets or sets the name property of a DOM object; it only applies to the following elements: <a>, <applet>, <button>, <form>, <frame>, <iframe>, <img>, <input>, <map>, <meta>, <object>, <param>, <select>, and <textarea>.

Note: The name property doesn't exist for other elements; unlike tagName and nodeName, it is not a property of the Node, Element or HTMLElement interfaces.

name can be used in the document.getElementsByName() method, a form and with the form elements collection. When used with a form or elements collection, it may return a single element or a collection.

Syntax

HTMLElement.name = string;
var elName = HTMLElement.name;

var fControl = HTMLFormElement.elementName;
var controlCollection = HTMLFormElement.elements.elementName;

Example

<form action="" name="formA">
  <input type="text" value="foo">
</form>

<script type="text/javascript">

  // Get a reference to the first element in the form
  var formElement = document.forms['formA'].elements[0];

  // Give it a name
  formElement.name = 'inputA';

  // Show the value of the input
  alert(document.forms['formA'].elements['inputA'].value);
 
</script>

Notes

In Internet Explorer (IE), the name property of DOM objects created using document.createElement() can't be set or modified.

Specification

W3C DOM 2 HTML Specification:

문서 태그 및 공헌자

 최종 변경: Sheppy,