问问题
2079 次
2 回答
4
How about this:-
Demo
$('body:contains("•")').contents().each(function () {
if (this.nodeType == 3) {
$(this).parent().html(function (_, oldValue) {
return oldValue.replace(/•/g, "<span class='bullets'>$&</span>")
})
}
});
Try avoid using *
. probably even body
. Try using the outermost container as possible.
This should also work
Demo
$('body:contains("•")').contents().each(function () {
if (this.nodeType == 1) { //Look for only element Nodes
$(this).html(function (_, oldValue) {
return oldValue.replace(/•/g, "<span class='bullets'>$&</span>")
})
}
于 2013-05-29T00:55:07.587 回答
0
$("*").each(function() {
if($(this).children().length==0) {
$(this).html($(this).html().replace(/•/g, '<span class="bullets">•</span>'));
}
});
This answer is based of this question
于 2013-05-29T00:55:20.883 回答