jQuery find/replace without changing original text
<p>Is there a way in jQuery to find a string of text in jQuery and not replace it with something else but wrap that text with an element so when the script is finished it spits out the original text with the string of text wrapped.</p>

<p>Example:</p>

<p>Original Text</p>

<pre><code>"Hello world to all people"
</code></pre>

<p>Search string</p>

<pre><code>"world to"
</code></pre>

<p>Replace with <code>&lt;i&gt;&lt;/i&gt;</code></p>

<p>Final output</p>

<pre><code>"Hello &lt;i&gt;World to&lt;/i&gt; all people"
</code></pre>

<p>Thanks in advance for the help!</p>

<p>Kind of working code:</p>

<pre><code>function highlightChild(child) {
        $(childElements[child]).text("");
        console.log(child);
        $('.child_element_' + child).bind('textselect', function(e){
            var selection = e.text;
            var str = $("#construct_version").text();
            var wrap = jQuery(childElements[child]).text(selection);
            var re = new RegExp("" + selection + "", "g");

            console.log(str.replace(selection, function(match, key, val){
                console.log(match);
                console.log(key);
                console.log(val);
                jQuery(childElements[child]).text(val)
            }));
        });
    }
</code></pre>

<p>The above code does the replace but where it actually does the replace it shows as undefined.</p>

<p>So if the original string is Hello world to all and I am wanting to replace world to with <code>&lt;b&gt;world to&lt;/b&gt;</code>, it shows in the console.log as Hello undefined all </p>
