I need to hide the special character #, using regex I'm this far. It is now removing break tags, as well as font-awesome characters, and possibly a number of other things.
Any ideas?
Thanks!
<p>#hello ## <i class="fa fa-map-marker"></i><br>secondline</p>
$("p").text(function() {
return $(this).text().replace(/(#)/g, '');
});
You're using text()
instead of html()
so it's not your regex but it's jQuery to remove the tags
$("p").html(function() {
return $(this).html().replace(/(#)/g, '');
});
Try using .html() instead of .text() - that'll strip your HTML out:
$("p").html(function() {
return $(this).html().replace(/\#/g,'');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.