I am trying to "highlight" specific words in a string after the string has been created.
I'm doing this currently:
var keywords = [
"Monday",
"monday",
"Tuesday",
"tuesday",
"Wednesday",
"wednesday",
"Thursday",
"thursday",
"Friday",
"friday",
"Saturday",
"saturday",
"Sunday",
"sunday"
];
function highlightImportant(that) {
that.find('.email-container').each(function(){
var full_text = $(this).text();
$.each(keywords, function(i){
full_text = full_text.replace(keywords[i], "<b>"+keywords[i]+"</b>");
$(this).text(full_text);
});
});
}
this function is called at the end of this:
function getEmails(email, name) {
console.log("working...");
$('.contact--details__show__emails').empty();
$.post('php/contacts-get-email.php', {email:email}, function(data) {
var email_body = data.split("<:>");
$.each(email_body.reverse(), function(i){
if(email_body[i]) {
var direction = email_body[i].split(':dir:')[0];
var email_text = email_body[i].split(':dir:')[1].split(':date:')[0];
var email_date = email_body[i].split(':dir:')[1].split(':date:')[1];
var d = new Date(0);
d.setUTCSeconds(email_date);
if(direction === "TO"){
var initial = "Us";
} else {
var initial = name;
}
var email_block = $('<div class="emailBlock dir-'+direction+'" style="opacity:0;">\
<div class="avatar">'+ initial +'</div>\
<div class="email-container">'+email_text+'</div>\
<div class="date">'+d+'</div>\
</div>');
$('.contact--details__show__emails').append(email_block);
email_block.delay(100*i).animate({"opacity":"1"}, 500);
highlightImportant($('.contact--details__show__emails'));
}
});
});
}
This seems like it should work, and when I console.log the event, I see it running through each keyword for every container, but it seems it's not finding the keywords even when they exist.
What I'd like to see happen is when I have a string like this:
var string = "Let's meet Monday or Tuesday";
I'd like to have them turn bold, like so:
"Let's meet Monday or Tuesday"
Any thoughts?
.replace(...)returns a new string ->full_text = full_text.replace(...)