I've created the following script that searches the page for any instances of "Two words" and replaces the space with a non-breaking space:
var search = $('body').html();
search = search.replace(/Two words/g, function($1) {
return ('<span class="no-break">' + $1 + '</span>');
});
$('body').html(search);
$(document).ready(function() {
$('.no-break').each(function() {
var $this = $(this);
$this.text($this.text().replace(/ /g, '\u00A0'));
});
});
However, when I place it onto my website, it's causing other jQuery and javascripts not to work.
Is there a better solution to mine? Something that won't upset the other scripts on my site.
$(document).ready()... jsFiddle does that automatically. Can you show an example of where this is not working?