You are here: Reference > JavaScript > client-side > HTML DOM > properties > name (abbr, acronym, address, ...)
name property (abbr, acronym, address, ...)
Sets or retrieves the name of an element.
The name property has different meanings for HTML elements:
- for form controls, it affects the contents of the message submitted to the server. See the name (form controls) property for details.
- for anchor elements, it specifies the name for a target anchor. See the name (anchor) property for details.
- for frame elements, it specifies the initial name for the contained window. See the name (frames) property for details.
- for image maps, it helps to establish a relationship between an image and an image map. See the name (map) property for details.
- for meta elements, use it together with the content property to create a well-defined meta tag. See the name (meta) property for details.
- for param elements, it contains information about the data that is passed in the value property to the object. See the name (param) property for details.
In Firefox, Opera, Google Chrome and Safari, all HTML elements support the name property.
In Internet Explorer, the elements mentioned above and some other HTML elements support this property.
You can find the browser support of the name property for a HTML element on the page for the HTML element.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: name |
Possible values:
String that sets or retrieves the name of the element.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the getElementsByName method:
|
||||
<head> <script type="text/javascript"> function CollectByName () { var tags = document.getElementsByName ("regFrom"); var count = tags.length; alert ("There are " + count + " element(s) with the specified name attribute: " + tags[0].name); } </script> </head> <body> <form name="regFrom" action="#URL#" method="post"> <input type="radio" name="sex" value="female" />female <br /> <input type="radio" name="sex" value="male" />male </form> <form name="regFrom" action="#URL#" method="post"> User Name: <input type="text" name="userName" /> <br /> Password: <input type="password" name="password" /> </form> <br /><br /> <button onclick="CollectByName ()">Collect elements by name</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
abbr, acronym, address, applet, area, b, base, bdo, bgsound, big, blink, blockquote, body, br, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, img, input:image, ins, kbd, label, legend, li, link, listing, marquee, menu, nobr, noframes, noscript, object, ol, optgroup, option, p, plaintext, pre, q, s, samp, script, small, span, strike, strong, style, sub, sup, table, tbody, td, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xmp
Related pages:
External links:
name attribute (MSDN)
form name attribute (Mozilla Developer Center)
general elements name attribute (Mozilla Developer Center)
name (Safari Reference Library)
form name attribute (W3C)
image name attribute (W3C)
form name attribute (Mozilla Developer Center)
general elements name attribute (Mozilla Developer Center)
name (Safari Reference Library)
form name attribute (W3C)
image name attribute (W3C)
User Contributed Comments