i have the following code:
function getArticleContent() {
var toPromote = 'example';
var toReplace = '<a href="/tags/'+toPromote+'">'+toPromote+'</a>';
var content = $(".a-entry").text();
if (content.search(toPromote) > -1)
{
$('.a-entry').html($('.a-entry').html().replace(new RegExp(toPromote, "g"), toReplace) );
}
else
{
//
}
}
$(document).ready(function() {
getArticleContent();
});
The code works fine, but if an image, or link has an title or alt attribute equal with the text that i want to replace the html it's broken, because the script put's the link in the alt, or title tag.
Best regards
I am trying to do something like this:
<div id="article">
<p>Some text here, bla bla.</p>
</div>
After the JS function i want to be:
<div>
<p>Some text <a href="/tags/here">here</a>, bla bla.</p>
</div>