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

133
Visualizações
I wanted to make a search box using JavaScript. All of my codes seems perfect for me. But, it's not working properly

May be there is some silly mistake I made. It's been 2 days I can't figure out the error. Here is what I want to achieve: When I type something on my search box the blocks which matches with my search there display will be block and others display will be none. Here is my HTML below.

<form class="d-flex">
  <input id="searchInput" class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
  <button class="btn btn-outline-success" type="submit">Search</button>
</form>

Here is the JavaScript Code. The problem is actually here. From the includes part it's not working properly.:

const search = document.getElementById('searchInput');
search.addEventListener('input', function(){
    const inputValue = search.value.toLowerCase();
    const noteCard = document.getElementsByClassName('cards');
    Array.from(noteCard).forEach(function(element){
        const cardTxt = element.getElementsByTagName('p')[0].innerText;
        console.log(typeof cardTxt)
        if(cardTxt.includes(inputValue)){
            console.log("yes included");
            element.style.display = 'block';
        }
        else{
            console.log('not included')
            element.style.display = 'none';

        }
    })
})

You may think what is cards, please have a look:

let html= "";
    noteArray.forEach(function(element, index){
        html +=`
        <div class="card my-2 mx-2 cards" style="width: 18rem;">
        <div class="card-body">
          <h5 class="card-title">Note ${index + 1}</h5>
          <p class="card-text">${element}</p>
          <button id=${index} onclick="deleteNote(this.id)" class="btn btn-primary">Delete Note</button>
        </div></div>
        `;

I can't find a error. If you can figure it out. Please let me know. You may need to see the full code. Here is my codepen link: https://codepen.io/techsinkv1/project/editor/Zvdvrg

about 4 years ago · Juan Pablo Isaza
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