次のコードのようなセレクターを含むJQuery を使用できます。
http://jsfiddle.net/z4ZwF/
function replaceText(textToSearch,classToApply)
{
$('div').html($('div').html().replace(new RegExp(textToSearch, 'g'),"<span class='"+classToApply+"'>"+textToSearch+"</span>"));
}
例 :replaceText("'lorem ipsum'",'red')
またはreplaceText("line",'red')
編集
検索と置換に引用符の折り返しを追加します: http://jsfiddle.net/z4ZwF/3/
function replaceText(textToSearch,classToApply,searchAndWrapQuote)
{
searchAndWrapQuote = searchAndWrapQuote || false;
quote = (searchAndWrapQuote) ? "'" : "";
$('div').html($('div').html().replace(new RegExp(quote+textToSearch+quote, 'g'),"<span class='"+classToApply+"'>"+quote+textToSearch+quote+"</span>"));
}
replaceText("lorem ipsum",'red',true)