Can I get your opinions on all of these?
If you had to pick one of these, or one of your own, which way written do you like the best?
What would be the best way in your judgment?
Which would be a good configuration?
For it to be set up one way.
Maybe you might have a different way you might write it.
1)
document.querySelectorAll('button[data-id]').forEach(function(button) {
button.addEventListener('click', function(e) {
const videoContainer = document.querySelector('.video');
videoContainer.setAttribute('data-id', button.getAttribute('data-id'))
});
});
2)
document.querySelectorAll('button[data-id]').forEach(function(button) {
button.addEventListener('click', function (e) {
document.querySelector('.video').dataset.id = e.target.dataset.id;
});
});
3)
const playButtons = document.querySelectorAll('button.cover');
function buttonClick(event) {
var videoContainer = document.querySelector('.video');
const button = event.target.getAttribute('data-id');
videoContainer.setAttribute('data-id', button)
}
for (const button of playButtons) {
button.addEventListener('click', buttonClick);
}
4)
const playButtons = document.querySelectorAll('button.cover');
function buttonClick(event) {
const videoContainer = document.querySelector('.video');
const att = event.target.getAttribute('data-id');
videoContainer.setAttribute('data-id', att)
}
for (let i = 0; i < playButtons.length; i++) {
const button = playButtons[i];
button.addEventListener('click', buttonClick);
}
5)
const playButtons = document.querySelectorAll('button.cover');
function buttonClick() {
const videoContainer = document.querySelector('.video');
const att = this.getAttribute('data-id');
videoContainer.setAttribute('data-id', att)
}
for (let i = 0; i < playButtons.length; i++) {
const button = playButtons[i];
button.addEventListener('click', buttonClick);
}
6)
const button = document.querySelectorAll('button.cover');
button.forEach(function addToPlayers(button, cover) {
button.addEventListener('click', function() {
var videoContainer = document.querySelector('.video');
videoContainer.setAttribute('data-id', button.getAttribute('data-id'))
});
});
7)
document.querySelectorAll('button[data-id]').forEach(function(button) {
button.addEventListener('click', function() {
const videoContainer = document.querySelector('.video');
videoContainer.setAttribute('data-id', button.getAttribute('data-id'))
});
});