Reputation: 35
I'm trying to hide a ','
(comma) that appears multiple times on a CMS-generated page. See the page here:
http://www.ucd.ie/earth/sandbox/test/01.html
I have tried the following code just before the tag (without success):
<script language="javascript">
var container = $(".hide-comma");
var result = container.html().replace(/,/g, "");
container.html(result);
</script>
Upvotes: 0
Views: 239
Reputation: 487
Enter the below code after load page completed:
$('.team-description').each(function(i , v){
var t = $(v).html().replace(/,/g, '');
$(v).html(t);
});
and see below link https://jsfiddle.net/sajjadgol/xpvt214o/881975/
Upvotes: 2
Reputation: 6558
I think you want to replace all the "," inside the div. so you can do like this.. get html inside the div then replace all the ','
function replaceComma(){
$('#divWithComma').html($('#divWithComma').html().replace(",",""));
console.log('replaced the comma, if you want to see hiding the comma please run the snippet again');
}
function hideComma(){
let text = $('#divWithComma').html();
let stringArray = text.split(',');
let finalHtml = "";
for(let i = 0; i<stringArray.length-1; i++){
finalHtml += stringArray[i] + '<span style="display:none;aria-hidden=true">,</span><p></p>';
}
$('#divWithComma').html(finalHtml);
console.log("yes hide the comma");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='divWithComma'>
<p>,</p>
<input type='button' onclick='replaceComma()' value='replace comma' />
<input type='button' onclick='hideComma()' value='hide comma' />
</div>
Upvotes: 1