Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
How to change videos on clicking it just goes blank

I'm trying to build a video player that works everywhere.

<div class="container">
<div class="main-video">
    <div class="video">
        <video src="gal/video1.mp4" controls muted autoplay></video>
        <h3 class="title">01. video 1</h3>
    </div>
</div>
<div class="video-list">
    <div class="vid active">
        <video src="gal/video1.mp4" muted></video>
        <h3 class="title">01. video 1</h3>
    </div>
    <div class="vid">
        <video src="gal/video2.mp4" muted></video>
        <h3 class="title">02. Title for video 2</h3>
    </div>
    
</div>

</div>

But now I also want some kind of playlist/menu along with the video player, from which I can select other videos. Those should be opened within my player right away. So I will have to "dynamically change the source of the video" But the problem is the videos don't change on clicking it just goes blank and I have to reload the page. This is the js code

<script>
let listVideo = document.querySelectorAll('.video-list .vid');
let mainVideo = document.querySelector('.main-video video')
let title = document.querySelector('.main-video .title')
listVideo.forEach(video =>{
    video.onclick = () =>{
        listVideo.forEach(vid => vid.classList.remove('active'));
        video.classList.add('active');
        if(video.classList.contains('active')){
            let src = video.children[0].getAttribute('src');
            mainVideo.src = src;
            let text = video.children[1].innerHTML;
            title.innerHTML = text;
        };
    };
});
</script>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!