For example we have
<p>Hey My Name is Thalapathy. I live in +++America+++. </p>
In here we want to hide +++ .
Result must look like
My Name is Thalapathy. I live in America
find in all the elements if this +++ occurs and use regex to replace whatever you want, something like this. and it will work on all the elements in body, where ever this +++, 3 plus will occur, it will be removed.
$("body").children().each(function () {
$(this).html( $(this).html().replace(/\+\+\+/g,"") );
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Hey My Name is Thalapathy. I live in +++America+++. </p>
and if you don't want to use jQuery then go for this. use Treewalker for the same.
const treeWalker = document.createTreeWalker(document.body);
while (treeWalker.nextNode()) {
const node = treeWalker.currentNode;
node.textContent = node.textContent.replace(/\+\+\+/g, '');
}
<p>Hey My Name is Thalapathy. I live in +++America+++. </p>
If the characters are known and constant (always the same)- then you can do a simple replace - note that you will need to escape the characters. Also note the "g" in the regex / replace - this will allow the replacement globally in the string.
const text="Hey My Name is Thalapathy. I live in +++America+++."
const newText = text.replace(/\+\+\+/g,'');
document.querySelector("#result").textContent = newText;
<p id="result"></p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With