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

137
Visualizações
Highlighting search keyword

I created a simple database and there is a live search,i want to know how to highlighting search keywords in the table. I've been using other means but still it doesn't work. please help me

this is my code :

$(document).ready(function(){
    load_data();

    function load_data(search){
      $.ajax({
        url:"get_data.php",
        method:"POST",
        data: {
          search: search
        },
        success:function(data){
          $('#hasil').html(data);
        }
      });
    }
    $('#search').keyup(function(){
      var search = $("#search").val();
      load_data(search);
    });


    function highlight_word(hasil)
      {
          var text = document.getElementById("search").value;
          if(text)
          {
              var pattern=new RegExp("("+text+")", "gi");
              var new_text=hasil.replace(pattern, "<span class='highlight'>"+text+"</span>");
              document.getElementById("hasil").innerHTML=new_text; 
          }
      }

html :

  <input type="text" class="form-control" id="search" name="search" >
  <div id="hasil"></div>
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You've never called highlight_word() function somewhere. you may replace your success function via:

success:function(data){
      $('#hasil').html(data);
      highlight_word(data);
    }
over 4 years ago · Santiago Trujillo Relatório

0

Follow This Article. You could this way

[https://stackoverflow.com/questions/8644428/how-to-highlight-text-using-javascript][1]

over 4 years ago · Santiago Trujillo 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