Reputation: 47
I'm working on an inline squirrel parse for syntax highlighting and I had been trying to use .code:contains and .wrap with a span to select an inline word. Example:
<div class="code">
function Entity::MoveTo(newx,newy,newz)
{
x = newx;
y = newy;
z = newz;
}
</div>
With this line of jQuery:
$(".code:contains('function')").wrap('<span class="function"></span>');
This turns the whole div red, rather that just the word 'function'. Any suggestions? Thanks in advance!
Upvotes: 1
Views: 179
Reputation: 16460
Something like this? :
var text = $(".code").text();
text = text.replace('function','<span class="function">function</span>');
$(".code").html(text);
Upvotes: 2