I want to find a string of text in an element and wrap some span tags round it. E.g.
From:
<h2>We have cows on our farm</h2>
To:
<h2>We have <span class='smallcaps'>cows</span> on our farm</h2>
I've tried:
$("h2:contains('cow')").each(function() {
$(this).text().wrap("<span class='smallcaps'></span>");
});
But that only wraps the whole containing h2
tag.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…