Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
Search with id mechanism in javascript

I have a problem implementing search feature in my project. I have html like:

Html:

<input type="text" id="search">
<video src="smth.mp4" id="firstvid">
<video src="smth2.mp4" id="secondvid">
<video src="smth3.mp4" id="thirdvid">

The js I tried:

var inp = document.getElementById("search")
var inpval = inp.value;
var except = document.querySelector('video')
var vidid = except.getAttribute(id)
if(inpval !== vidid){
except.style.display="hide";
}else{
except.style.display="block";
}

I know it is dumb. All i want is that when user types id of a video in search bar, let's say firstvid, only firstvid should appear while all other videos should disappear. Is it possible with js? I searched a lot but could not find any example.

By appearing and disappearing, I meant that the search bar is on top of page and the videos are under it just like youtube. So when id of a video is searched all other videos should hide.

Thanks in advance :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have solved the issue in the sense. When user types in the input field. If the input field value matches with the id of the video tag then it will set the display property of the video tag from none to block

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<input type="text" id="search" oninput="getTheValue()">
<video src="Proof.mp4" id="firstvid" style="display: none;"> </video>
<video src="Proof.mp4" id="secondvid" style="display: none;"></video>
<video src="Proof.mp4" id="thirdvid" style="display: none;"></video>
</body>
<script>

function getTheValue() {
    var inp = document.getElementById("search")  //getting input field

    if (inp.value == 'firstvid') {  // if it is equal to first id 
        document.getElementById('firstvid').style.display = "block";  
        //setting display to block
    }
    else if (inp.value == 'secondvid') {
        console.log("in second")
        document.getElementById('secondvid').style.display = "block";
    }
    else if (inp.value == 'thirdvid') {
        console.log("in third")
        document.getElementById('thirdvid').style.display = "block";
    }
    else {
        document.getElementById('firstvid').style.display = "none";
        document.getElementById('secondvid').style.display = "none";
        document.getElementById('thirdvid').style.display = "none";
    }
}
</script>

</html>

You can just copy paste and run to see. Attached screenshot

enter image description here

Like the above

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda