Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
How can I change the source of a video after clicking a specific h3 tag?

enter image description hereSo I'm currently trying to make a video streaming site but I'm a bit stuck.

I'm trying to make the episode selector change the source of the video but I am a little confused as to how I can make it change the source of the player. I'm also trying to make the text below the player change depending on which video is selected.

    <div class="container">
        <div class="main-video">
            <div class="video">
                <video src="video link here"></video>
                <h3 class="ep-title">00. Prologue</h3>
            </div>
        </div>

        <div class="episode-list">
            <div class="episode active">
                
                <img src="image link here" alt="">
                <h3 class="title">00. Prologue</h3>
            </div>
            <div class="episode">
                <img src="image link here" alt="">
                <h3 class="title">01. A Winter Day, A Fateful Night</h3>
            </div>
            
            </div>
        </div>
    </div>

<script>
    let listVideo = document.querySelectorAll('.episode-list .episode');
    let mainVideo = document.querySelector('.main-video video');
    let title = document.querySelector('.main-video .title')

    listVideo.forEach(video =>{
        video.onclick = () =>{
            listVideo.forEach(episode => episode.classList.remove('active'));
            video.classList.add('active');
            };
        
    });
</script>

This is what my code for the page (excluding the nav bar and plyr code) currently looks like. I do apologise beforehand as my question might be a bit complicated (I lack braincells lol) but any help is appreciated :)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

const btn = document.getElementById('change-url');
const video = document.getElementById('video');


btn.addEventListener('click',()=>{
   console.log(video)
   video.setAttribute('src','http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4');
})
<button id="change-url">change url</button>
<br/><br/>

<video id="video" src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" width="300px" controls autoplay></video>

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think mainVideo.setAttribute('src', YOURSOURCELINK); should change the video src. To change the text of the title you can use title.innerHTML = "NEWTEXT"

An example for this could be:

the "index" argument is the index in the list (keep in mind js starts with 0 for the first index), so to get episode one you would use changeVideo(0), for episode two changeVideo(1) etc

var list = [{
    title: "Episode 1",
    src: "some source link"
},{
    title: "Episode 2",
    src: "seconde source link"
}];


function changeVideo(index){
    let mainVideo = document.querySelector('.main-video video');
    let title = document.querySelector('.main-video .title')

    mainVideo.setAttribute("src", list[index].src)
    title.innerHTML = list[index].title

}

then you would need a onclick event in your video select, for example add onclick="changeVideo(1)" in your <div class="episode">

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda