ive been doing this for a week. still couldnt find the answer. i am trying to convert only some of the keyword to link instead of all. for example if theres 7 keywords in a paragraph, how can i only convert 3 of it? can someone help? please
currently this is my code.
(function($) {
$.fn.replacetext = function(target, replacement) {
// Get all text nodes:
var $textNodes = this
.find("*")
.andSelf()
.contents()
.filter(function() {
return this.nodeType === 3 &&
!$(this).parent("a").length;
});
$textNodes.each(function(index, element) {
var contents = $(element).text();
contents = contents.replace(target, replacement);
$(element).replaceWith(contents);
});
};
})(jQuery);
$("p").replacetext(/\bdress\b/gi, "<a href='http://www.google.com'>$&</a>");