0

I am trying to highlight search results as searched from input.

Highlight is working well but it does not handle special characters like (**) etc. I am getting error

SyntaxError: nothing to repeat

jQuery Used to highlight is:

$(function() {

  $("#search").on("input", function() {

    var ths = $(this);
    hightlight(ths.val());
  });

});

function hightlight(txt) {

    $(".search-results tr td div").each(function (i, v) {
        var regex = new RegExp( '(' + txt + ')', 'gi' );
        v.innerHTML = v.innerText.replace(regex, "<strong>$1</strong>");
    });

}

I have made a demo on Plunker

Link Here

Gags
  • 3,759
  • 8
  • 49
  • 96

0 Answers0