Question: 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'));
    });
});​

```

<http://jsfiddle.net/Ggkpb/>

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.

Answer: 
Here's another way of writing it.
Since you didn't post an error messages, then I'm sure if this fixes your problem.

```
$(function(){
    $('body').html(function(){
        return $(this).html().replace(/Two words/g, '<span class="no-break">Two words</span>');
    }); 
    $('.no-break').each(function () {
        $(this).text($(this).text().replace(/ /g, '\u00A0'));
    });
});

```
I think it's better if you separate your text from your javascripts. You could mark every block of text in your page using a Class

```
<div class="text">abcxyz...Two words...</div>

```

and then call

```
$('.text').each(function(){
      var search = $(this).html();
      search = search.replace(/Two words/g, function($1) {
            return ('<span class="no-break">' + $1 + '</span>');
      });
      $(this).html(search);
});

```