包裹单词inline jquery



我正在为语法突出显示的内联松鼠解析工作,我一直在尝试使用.code:cod:contains and。contains and。用跨度选择一个inline word。示例:

<div class="code">
    function Entity::MoveTo(newx,newy,newz)
{
    x = newx;
    y = newy;
    z = newz;
}
</div>

使用此jQuery行:

$(".code:contains('function')").wrap('<span class="function"></span>');

这会变成整个Div红色,而只是"函数"一词。有什么建议么?预先感谢!

类似的东西?:

var text = $(".code").text();
text  = text.replace('function','<span class="function">function</span>');
$(".code").html(text);

最新更新