Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove ' '

I'm looking for a way to delete ' ' from my html code, found number of ways on stackoverflow.com, but neither of those seam to work!

HTML

<p>No Space</p>
<p>&nbsp;1 Space</p>
<p>&nbsp;&nbsp;2 Spaces</p>
<p>&nbsp;&nbsp;&nbsp;3 Spaces</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;4 Spaces</p>

jQuery

$(document).ready(function() {

    $('p').text().replace(/ /g, '');
    //$('p').html($(this).html().replace(/&nbsp;/gi,''));

});

jsfiddle - playground http://jsfiddle.net/MrTest/hbvjQ/85/

like image 844
Iladarsda Avatar asked Sep 09 '25 12:09

Iladarsda


1 Answers

You have &nbsp in your code instead of &nbsp;

$('p').each(function(){
    $(this).html($(this).html().replace(/&nbsp;/gi,''));
});

http://jsfiddle.net/genesis/hbvjQ/76/

like image 139
genesis Avatar answered Sep 11 '25 01:09

genesis