jQuery - setting an element's text only without removing other element (anchor)
<p>I have an element like this:</p>

<pre><code>&lt;td&gt;
  &lt;a&gt;anchor&lt;/a&gt;
  [ some text ]
&lt;/td&gt;
</code></pre>

<p>And i need to set it's text in jQuery, without removing the anchor.</p>

<p>The element's contents could vary in order (text before or after), and the actual text is unknown.</p>

<p>Thanks</p>

<p><strong>New Update</strong></p>

<p>This is what i came up using, assumes only a single text node:</p>

<pre><code>    function setTextContents($elem, text) {
        $elem.contents().filter(function() {
            if (this.nodeType == Node.TEXT_NODE) {
                this.nodeValue = text;
            }
        });
    }

    setTextContents( $('td'), "new text");
</code></pre>
