QP School

Full Version: Select elements by name in JavaScript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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>");