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
<div ><a href="https:google.com">here</a>, <a href="https:google.com">new</a>, <a href="https:google.com">test</a></div>
CodePudding user response:
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 ><a href="https:google.com">here</a>, <a href="https:google.com">new</a>, <a href="https:google.com">test</a></div>