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

149
Views
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
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!