Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

using getElementsByName() together with document.getElementById() or alternative approach?

$
0
0

I am trying to find all HTML tags with a specific name "name" inside an element with a specific id.

document.getElementById("myid").getElementsByName("name");

throws error getElementsByName is not a function

The sample code is:

<!DOCTYPE html><html><body><div id="myid"><p name="name">first name</p><p name="name">first name</p></div><p id="result">RESULT</p><script>    let el = document.getElementById("myid")    let names=el.getElementsByName("fname");    document.getElementById("result").innerHTML = elements[0].innerHTML;</script></body></html>

I saw somewhere that unlike other functions the 'getElementsByName' is limmited to 'Document' scope only and does not exist in any other scope.

  1. is this true?
  2. what alternative approach should I use instead of 'getElementsByName'?

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>