jQuery Hide part of a string based on text
contains, hide, jquery
Solution
If you want to actually remove the text, use:
$('div.text').text(function (i, t) {
return t.replace(' Hide Me', '');
})
jsFiddle example
To hide it, use:
$('div.text').html(function (i, t) {
return t.replace('Hide Me', '<span class="hidden">Hide Me</span>');
})
with the CSS `.hidden { display:none; }`
jsFiddle example
Problem
If you have HTML like: ``` <div class="text">Good Stuff Hide Me</div> <div class="text">Great Stuff Hide Me</div> <div class="text">Best Stuff Hide Me</div> ``` and want to hide just "Hide Me" in every instance of div.text so you're left with Good Stuff Great Stuff Best Stuff How would you do that with jQuery? This `$("div:contains('Hide Me')").hide();` hides the entire string. How can you isolate the text you want to hide?