HTML DOM getElementsByName() Method

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP







<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]
-->



HTML DOM getElementsByName() Method


❮ Document Object



Example


Get all elements with the specified name:



var x =
document.getElementsByName("fname");

Try it Yourself »

More "Try it Yourself" examples below.



Definition and Usage


The getElementsByName() method returns a collection of all elements in the document with the specified
name (the value of the name attribute), as a NodeList object.


The NodeList object represents a collection of nodes. The nodes can be accessed by index numbers. The index starts at 0.


Tip: You can use the
length property of the NodeList object to determine the number of elements
with the specified name, then you can loop through all elements and extract the
info you want.


Note: In HTML5, the "name" attribute is deprecated and has
been replaced by the "id" attribute for many elements. Use the
document.getElementById() method where it is appropriate. Also look at the
getElementsByClassName() and
getElementsByTagName()
methods.



Browser Support














Method
getElementsByName() Yes Yes Yes Yes Yes

Syntax



document.getElementsByName(name)

Parameter Values








ParameterType Description
nameStringRequired. The name attribute value of the element you want to access/manipulate




<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]
-->




Technical Details






DOM Version: Core Level 1 Document Object
Return Value: A NodeList object, representing a collection of elements with the specified name. The elements in the
returned collection are sorted as they appear in the source code.

More Examples




Example


Find out how many elements there are in the document that have a name
attribute with the value "animal" (using the length
property of the NodeList object):



var x =
document.getElementsByName("animal").length;

Try it Yourself »



Example


Check all <input> elements with type="checkbox" in the document that have a name
attribute with the value "animal":



var x = document.getElementsByName("animal");
var i;
for (i = 0; i < x.length; i++)

  if (x[i].type == "checkbox")
    x[i].checked = true;
  

Try it Yourself »



❮ Document Object

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)