You can use contains to find elements that contain the selected text, then iterate over each one, replacing the text with the new text with a wildcard based on your search string. Keep in mind that contains will return a match even if descendant elements contain text, so you should probably specify some type of element if you have nested elements or a filter based on whether the element contains internal elements.
$('div:contains("bla-bla")').each( function() { var txt = $(this).text(); var insert = 'bla-bla<a href="...">(link)</a>'; $(this).text( txt.replace( /bla-bla/g, insert ) ); });
or
$(':contains("bla-bla")') .filter( function() { return $(this).children().length == 0; } ) .each( function() { var txt = $(this).text(); var insert = 'bla-bla<a href="...">(link)</a>'; $(this).text( txt.replace( /bla-bla/g, insert ) ); });
source share