Iladarsda Iladarsda - 6 months ago 26
jQuery Question

Remove ' ' - still trying

Still looking for a way to delete

' '
from my html code, found number of ways on stackoverlow.com, but neither of those seam to work!

HTML

<p>No Space</p>
<p>&nbsp1 Space</p>
<p>&nbsp&nbsp2 Spaces</p>
<p>&nbsp&nbsp&nbsp3 Spaces</p>
<p>&nbsp&nbsp&nbsp&nbsp4 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/

Any help much appreciated.

Pete

Answer

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/