Questions tagged [getelementsbyname]

In JavaScript and VBScript, the getElementsByName is a function which is used to access all HTML elements with a specified name. Two different elements can be declared with same name unlike their Id which must be defined unique. Tag getElementsByName can be used for usage related problems of getElementsByName function.

Wiki:

The getElementsByName() is a JavaScript and VBScript function which can be used in web pages to accesses html elements with their specified name. The getElementsByName method is supported in all major browsers. The function getElementsByName() can be used to access more than one element because html elements can be defined with same name unlike theirIDs which should be defined unique.

Syntax usage:

document.getElementsByName('name')

Example:

<!DOCTYPE html>
<html>
<head>
   <script type="text/javascript">
      function getElements()
      {
          var x=document.getElementsByName("x");
          alert(x.length);
      }
   </script>
</head>
<body>

Cats:
  <input name="x" type="radio" value="Cats">
Dogs:
  <input name="x" type="radio" value="Dogs">
  <input type="button" onclick="getElements()" value="Elements with name 'x'?">

</body>
</html>

Tag usage:

The tag can be used for programming problems related to usage of getElementsByName function. Tag should be avoided for theoretical and opinion based questions.

Read more:

134 questions
2
votes
1 answer

getElementsByName returns nodelist or htmlcollection

Totally new to javascript. Ran a getElementsByName query and got a nodelist, however I was looking for an htmlcollection. I know this is due to Dom level implementation. Qustion: Should I be testing for a return type to be sure or is there a better…
2
votes
4 answers

Changing CSS with DOM getElementsByName

I am trying to make changed to CSS with the DOM in JS, I have succeeded with changing the HTML attributes but not the CSS attributes. It seems that CSS is not affected by this particular DOM. Code looks like this...