I would like to open this up to the forum and try and get as many people’s thoughts on this.
Basically what I’m trying to find out is,
Is it better to group the selector together, or not.
Does keeping the selectors that match the handlers make more sense?
Like how this one is set up?
https://jsfiddle.net/192h0w85/123/
(function iife() {
"use strict";
const player = document.getElementById("player");
const button = document.getElementById("button");
button.addEventListener("click", function () {
if (player.paused) {
player.play();
} else {
player.pause();
}
});
const value = document.getElementById("input");
const sent = document.getElementById("sent");
sent.addEventListener("click", function () {
player.volume = 1.0;
player.src = value.value;
});
}());
As opposed to this?
Which would be grouping them altogether.
https://jsfiddle.net/192h0w85/122/
(function iife() {
"use strict";
const player = document.getElementById("player");
const button = document.getElementById("button");
const value = document.getElementById("input");
const sent = document.getElementById("sent");
button.addEventListener("click", function () {
if (player.paused) {
player.play();
} else {
player.pause();
}
});
sent.addEventListener("click", function () {
player.volume = 1.0;
player.src = value.value;
});
}());