Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

jQuery remove all URLs from the text in a div

$
0
0

I have some divs which contain URLs. I simply want to remove the URLs and replace them with something else, for example 'No URLs allowed'. I have used the replace method with jQuery, but it only replaces the http part of the link. How can I replace the whole URLs?

var text = $('#text1').text();

$('#text2').text(text.replace(/http/g, ''));
<script src="https://code.jquery.com/jquery-2.2.4.js"></script><div id="text1">This is my div with some http://example.com/ URLs in, I simply want to https://example.com remove all the URLs and replace them with 'no URLs allowed'</div><br><div id="text2"></div>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>