I am learning react and I have an array of strings that are classes of different elements,
let melody = ['a', 'c', 'f', 'g']
I am doing a piano and this is a list that conform a melody that should find each element that has the same class and play it getting the final melody. I would normally do it with something like (obviously with an interval and other stuff)
melody.forEach(note=> {
document.getElementsByClassName(note)[0].click()
})
I am not sure if this is the best way to achieve this in react, and if using getByClass if correct to use in cases like this. Thank you so much....
I'll advise the use of modern DOM syntax.
let clickButton = document.querySelectorAll('.note');
let melody = ['a', 'c', 'f'];
melody.forEach((note) => {
let newNote = document.querySelector("." + note);
newNote.addEventListener("click", () => {
alert("Hello world");
});
});