-1

I have four videos in one div and I have another one video in another div I have done an event listener that will apply for the all five video as you see

var videoAct = document.querySelectorAll('video'), mainVideo = document.getElementById('mainvideo'), // this id for the video in (mainV ) allVideo = document.getElementById('allvideo'), // this id for the div that contain the four video mainV = document.getElementById('mainv'); // this id for the div that contain one video videoAct.forEach(function(video) { video.addEventListener('mouseover', function() { this.play(); video.muted = true; }); video.addEventListener('mouseleave', function() { this.pause(); }); }) 

so how I remove this event listener from my one video in (mainV ) so that I work with its default setting

2

2 Answers 2

1

You don't have to remove your event, just don't apply it...

var allVideo = document.getElementById('allvideo'), // this id for the div that contain the four video videoAct = allVideo.querySelectorAll('video'); // look for videos only in the #allvideo div videoAct.forEach(function(video){ video.addEventListener('mouseover',function(){ this.play(); video.muted = true; }); video.addEventListener('mouseleave',function(){ this.pause(); }); }) 
Sign up to request clarification or add additional context in comments.

2 Comments

i try but it didn't work , it give me this error in console ( allVideo.forEach is not a function )
there is no allVideo.forEach() in the code I gave, so there is something wrong in your code, not in my answer... you should do forEach() on videoAct not on allVideo as videoAct contains list of video elements and allVideo is only a div that contains those video elements
0

You can check the id value of the video which you want to ignore inside the for loop so that the listener is not added to that video.

var videoAct = document.querySelectorAll('video'), mainVideo = document.getElementById('mainvideo'), // this id for the video in (mainV ) allVideo = document.getElementById('allvideo'), // this id for the div that contain the four video mainV = document.getElementById('mainv'); // this id for the div that contain one video videoAct.forEach(function(video){ if(video.id !== 'mainvideo') { video.addEventListener('mouseover',function(){ this.play(); video.muted = true; }); video.addEventListener('mouseleave',function(){ this.pause(); }); } }) 

3 Comments

thanks alot man it work just fine :)
@MohamedNagehOtafy glad to help. :)
if i want to change the source of the video with ( id = mainVideo ) to any source from the four video when i click on any of them i try to add this code to if statement but it didn't work --> videoAct.forEach(function(video){ if(video.id !== 'mainvideo') { video.addEventListener('mouseover',function(){ this.play(); video.muted = true; }); video.addEventListener('mouseleave',function(){ this.pause(); }); video.addEventListener('click', function(){ var source = this.hasAttribute('src').value; mainVideo.src = src[source]; }) } }) <--

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.