I am using following code to highlight text in div. But if I type something easy as "a", "img" or so, it will break the html output, images and break the site.
if ($('#block-multiblock-2 input').val().length !== 0) {
$('.group-informacie .field-name-body p').each(function() {
//Handle special characters used in regex
var searchregexp = new RegExp($("#block-multiblock-2 input").val().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "gi");
//$& will maintain uppercase and lowercase characters.
$(this).html($(this).html().replace(searchregexp, "<span class='highlight'>$&</span>"));
});
}
I think the problem lies within RegExp which has to somehow exclude html tags? I tried inserting <> or so characters which I found in other questions but nothing actually worked.
I am trying to make jquery search within text which is saved by users / ckeditor, which output is sometimes like:
<p><img src="..."/>Some super text <i>here</></p>
So it can contain any html output, headlines, divs, accordions etc.