How to remove   from the end of spans with a given class?

ezhil picture ezhil · Aug 5, 2014 · Viewed 17.6k times · Source

I need to remove the   after the value of given spans.
The HTML looks like this:

<span class="number">0.15&nbsp;</span>

The &nbsp; is coming from the server (CMS).

Is there any way to remove the &nbsp; by using CSS rules?

Answer

Manwal picture Manwal · Aug 5, 2014

You can't do this with only css. Somehow you have to use jquery for this. With Regular Expression you can simply do this.

var span = $('span').html();
span = span.replace(/&nbsp;/g, '');
$('span').html(span);

DEMO

Note: &nbsp; is coming from CMS them you have to use jquery code to replace it when your document loaded fully.

$(document).ready(function(){
    var span = $('span').html();
    span = span.replace(/&nbsp;/g, '');
    $('span').html(span);
});