I've written the following functions to remove non-breaking spaces from the html code in a SharePoint site (SharePoint designer litters whatever code you write with non-breaking spaces whenever you open the masterpage or page layouts! You end up spending all your time going back and deleting them).
In any case, it seems overly long, I'm quite new to jQuery and wondered if there is a cleaner way to perform the same task.
<script type="text/javascript">
$(function(){
$('h1').each( function() {
var $h = $(this);
var html = $h.html();
html = html.replace( ' ', '' );
$h.html( html );
});
});
$(function(){
$('h2').each( function() {
var $h = $(this);
var html = $h.html();
html = html.replace( ' ', '' );
$h.html( html );
});
});
$(function(){
$('h3').each( function() {
var $h = $(this);
var html = $h.html();
html = html.replace( ' ', '' );
$h.html( html );
});
});
$(function(){
$('h4').each( function() {
var $h = $(this);
var html = $h.html();
html = html.replace( ' ', '' );
$h.html( html );
});
});
$(function(){
$('p').each( function() {
var $h = $(this);
var html = $h.html();
html = html.replace( ' ', '' );
$h.html( html );
});
});
</script>