简体   繁体   中英

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

<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>

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>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM