I am using a slightly modified version of a converting a keyword to a link presented in another question here.
The code, with some omissions, is as following:
$(".keyword_search").each(function() {
var targetword = 'TEST';
var explanation = 'Is something you do to find out if stuff works';
//targetword and explanation actually defined in a loop, but omitted here
var content = $(this)[0];
var re = new RegExp("(\\b"+targetword+"\\b)", "gi");
content.innerHTML = content.innerHTML.replace(re,keywordconvert);
}
function keywordconvert(str, p1, offset, s ) {
return '<a href="#" data-toggle="tooltip" title="'+p1+'">'+p1+'</a>';
}
I have few questions about this code.
1) Where are the parameters of keywordconvert defined? str and p1 both contain the string to be replaced, offset contains the starting point of the word in the the content and s contains content.
2) How would I go about adding the explanation string to the title-class of the the link in the keywordconvert function? In other words, how can I add parameters to this function?
Any help would be appreciated, I've been scouring the web for answers for far too long.