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> 1 Space</p>
<p> 2 Spaces</p>
<p> 3 Spaces</p>
<p> 4 Spaces</p>
jQuery
$(document).ready(function() {
$('p').text().replace(/ /g, '');
//$('p').html($(this).html().replace(/ /gi,''));
});
jsfiddle - playground http://jsfiddle.net/MrTest/hbvjQ/85/
Any help much appreciated.
Pete
try
or if you wish to delete the   try
also please note that space is
and not   (you are missing ;)Based on bažmegakapa' answer, this can be used on elements containing other elements.
.text()
gets rid of html elements;.html()
does notHere's a non-jQuery answer, since using jQuery for such a task is overkill unless you're already using it for something else on your site:
You have   in your code instead of
http://jsfiddle.net/genesis/hbvjQ/76/
This one will replace every white-space character:
Or if you only want to replace non-breaking spaces:
jsFiddle Demo
I am setting the new value using a closure as a parameter for
.text()
.Please note that HTML entities need a closing
;
in the end.Here is the code:
And here is jsfiddle: http://jsfiddle.net/hbvjQ/62/