I need to detect element count number
I have 10 poster elements and I have a forEach
loop
I need the poster number that I clicked on, for example if I click on the seventh poster posternumber
should be 7
poster.forEach(p => {
p.addEventListener('click',function(){
videoTag.src = xResult[movieLanguageUrl][/*posternumber*/];
});
});
Get the index value on the second parameter of the forEach
function and it should work:
poster.forEach((p, index) => {
p.addEventListener('click', () => {
videoTag.src = xResult[movieLanguageUrl][index + 1];
});
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments