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

146
Visualizações
javascript search - hide text but can be searched

I did a search from a tutorial that can filter in any order of words.

My HTML Code

    <input type="text" class="search-box">
    <ul>
        @for (int i = 0; i < Movies.Count; i++)
          {
            var movieTitle = Movies[i].Title;
            var movieAuthor = Movies[i].Author;
            <li class="item-list">@movieTitle</li>
          }
    </ul>

My Script

let inputElem = document.querySelector(".search-box");
inputElem.addEventListener("input", handleInput, false);

function handleInput() {
    
    let inputElemValue = inputElem.value.toLowerCase();

    let inputWordsArray = inputElemValue.split(" ");

    let liHTMLCollection = document.getElementsByClassName("item-list");

    Array.from(liHTMLCollection).forEach((li) => {
        let innerTextLowerCase = li.innerHTML.toLowerCase();

        let matching = true;

        inputWordsArray.forEach((word) => {
            let regex = new RegExp("\\b" + word);

            if (regex.exec(innerTextLowerCase)) {
                //if true - display
            } else {
                //if false hide
                matching = false;
            }
        });
        if (matching) {
            li.style.display = "block";

        } else {
            li.style.display = "none";
        }
    });
}

What I want is to concatenate movieTitle and movieAuthor but I want movieAuthor to be hidden in front-end but can be searchable and will appear the movieTitle.

Thanks for answer

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