Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Removing specific text from an element

Tags:

jquery

I want to remove the text "By:" from an element in my website. I want the rest of the text to remain there. How can I achieve that with jQuery? Thank you.

The HTML

<div id="text">By: Anonymous From Minnesota</div> 

I want it to just be:

<div id="text">Anonymous From Minnesota</div> 
like image 647
henryaaron Avatar asked Dec 25 '11 05:12

henryaaron


1 Answers

If you wanted to find every element with "By:" in it and remove it, you could try this:

$(':contains("By:")').each(function(){     $(this).html($(this).html().split("By:").join("")); }); 

This removes any occurrence of "By:" in any element. If you want to target specfic type of elements, simply change $(':contains("By:")') to include whatever selector suits you.

like image 154
Andrew Odri Avatar answered Sep 20 '22 15:09

Andrew Odri