:
$("h3:contains('Some Text1'), h3:contains('Some Text2'), h3:contains('Some Text3')").each(function() {
$(this).append("<span>Some Text</span>");
});
OP , :
var text = "Some Text1, Some Text2, Some Text3";
text.replace(/\s?([^,]+?)(,)|\s([^,]+?)$/g, "h3:contains('$1$3')$2");
.
:
var text = "Some Text1, Some Text2, Some Text3";
text.replace(/\s?([^,]+?)(,)|\s([^,]+?)$/g, "h3:contains('$1$3')$2");
$(text).each(function() {
$(this).append("<span>Some Text</span>");
});
This will replace all terms separated by commas with the term itself surrounded by h3: contains ('and'). They will be separated by commas just like the original line.
source
share