Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select elements by name in JavaScript
#1
The HTML part between the <body></body> tags looks like this:

Code:
<!-- Select elements by name -->

<input type="radio" name="size" value="S"> S
<input type="radio" name="size" value="M"> M
<input type="radio" name="size" value="L"> L
<input type="radio" name="size" value="XL"> XL
<input type="radio" name="size" value="XXL"> XXL

The JavaScript part looks like this:

// Select elements by name

let elems = document.getElementsByName('size');
let sizes = [].map.call(elems, elem => elem.value);

document.write("<br>");
document.write(sizes);
document.write("<br>");
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Add elements at the beginning of an array in JavaScript Qomplainerz 0 352 04-04-2023, 07:37 AM
Last Post: Qomplainerz
  Add elements at the end of an array in JavaScript Qomplainerz 0 313 04-04-2023, 07:37 AM
Last Post: Qomplainerz
  Select elements by tag name in JavaScript Qomplainerz 0 326 04-04-2023, 07:35 AM
Last Post: Qomplainerz
  Select elements by class name in JavaScript Qomplainerz 0 349 04-04-2023, 07:33 AM
Last Post: Qomplainerz
  Select elements by ID in JavaScript Qomplainerz 0 343 04-04-2023, 07:23 AM
Last Post: Qomplainerz
  Select elements by CSS selector in JavaScript Qomplainerz 0 340 04-04-2023, 07:18 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 6 Guest(s)