이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!
Returns a nodelist collection with a given name
in the (X)HTML document.
Syntax
elements = document.getElementsByName(name)
elements
is a liveNodeList
Collectionname
is the value of thename
attribute of the element.
Example
<!DOCTYPE html> <html lang="en"> <head> ... </head> <body> <form name="up"><input type="text"></form> <div name="down"><input type="text"></div> <script> var up_forms = document.getElementsByName("up"); console.log(up_forms[0].tagName); // returns "FORM" </script> </body> </html>
Notes
The name
attribute is only applicable to (X)HTML documents. The method returns a live NodeList
Collection that contains all elements with a given value for the name attribute, such as <meta>
or <object>
or even if name
is placed on elements which do not support a name attribute at all.
The getElementsByName method works differently in different browsers. In IE & Opera, getElementsByName() method will also return elements that have an id attribute with the specified value. so you should be careful not to use the same string as both a name and an ID.
Specifications
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'Document.getElementsByName()' in that specification. |
Living Standard | |
Document Object Model (DOM) Level 2 HTML Specification The definition of 'Document.getElementsByName()' in that specification. |
Recommendation | Initial definition |
See also
document.getElementById()
to return a reference to an element by its IDdocument.querySelector()
for selectors via queries like'div.myclass'
문서 태그 및 공헌자
태그:
이 페이지의 공헌자:
cvrebert,
mattr,
madarche,
teoli,
AlfredoLlaquet,
Alexsey,
chtej91,
cse031sust02,
kscarfone,
Khodaidad_Basharmand,
ethertank,
Sheppy,
alex.w.y,
RobG,
Ms2ger,
George3,
Brettz9,
Amrittuladhar,
BenoitL,
Mgjbot,
Nickolay,
Jabez,
Pmash,
Ptak82,
Jonnyq,
Dria,
JesseW
최종 변경:
cvrebert,