How do I use a dynamic variable as first argument in replace
function?
I have this code that searches a user specified string:
var query = jQuery.trim(jQuery(this).val()).toLowerCase(); console.log(query +' was searched') jQuery('.one-reference').each(function () { var jQuerythis = jQuery(this); if (jQuerythis.text().toLowerCase().indexOf(query) === -1) { jQuerythis.fadeOut(); } else { jQuerythis.html(jQuerythis.html().replace(/&/g, '<strong>$&</strong>')); jQuerythis.fadeIn(); } });
This replace(/&/g, '<strong>$&</strong>'))
is not working.
I want to wrap all occurrences of query
with <strong>
tags.