Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove comma from a html div class?

I want to remove all commas from a HTML div class. is it possible to remove commas without modifying the HTML content via CSS or javascript?

div class

.test a:link {
    background-color: green;
}

HTML content

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div class="test"><a href="https:google.com">here</a>, <a href="https:google.com">new</a>, <a href="https:google.com">test</a></div>

>Solution :

This JS will replace the innerHTML of the div with a copy of itself where all instances of , have been replaced by an empty string (effectively deleted).

See String.replace(). This uses a very simple "regular expression" aka Regex to find all the commas.

const div = document.querySelector('.test');
div.innerHTML = div.innerHTML.replace(/,/g, '');
<div class="test"><a href="https:google.com">here</a>, <a href="https:google.com">new</a>, <a href="https:google.com">test</a></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading