I have slider and each slider contains video as background and play/pause buttons. Trying to play video by clicking proper button, but I get this behavior: I click play button from the second slide and video plays from the first slide. The same is for pause button. Advice please how can I fix this bug?
[].forEach.call(document.getElementsByClassName('play'), function(element, index) {
element.onclick = function() {
document.getElementsByTagName('video')[index].play();
}
});
I checked your fiddle. There is a bug in the way you are adding executing click callback. Based on the code you have, replace
document.getElementsByTagName('video')[index].play();
by
$(this).siblings().closest('video')[0].play();