I\'m generating content dynamically, so I\'m often ending up with documentFragments
which I\'m querying using querySelectorAll
or querySelector>
To not get into technicalities with array methods it can sometimes be more readable to make a list of node names and loop over the list.
In this example I assign the same event handler to all buttons in two different radio button groups (where each button in the group has the same name):
Phase
Ssr
Relay
Manual
Automatic
Sample event handler:
var evtRbtnHandler =
function rbtnHandler() {
document.getElementById("response11").innerHTML = this.name + ": " + this.value;
}
And assigning:
var buttongroup = ["acmode", "powermode"];
buttongroup.forEach(function (name) {
document.getElementsByName(name).forEach(function (elem) {
elem.onclick = evtRbtnHandler;
});
});
In any case once you get your hands on each single item it can be pushed() to an array using human readable code.