Replacing certain containers inside a cloned "div" in jquery
<p>I am trying to replace the contents of a selected "div" element, and append it to the parent control. So far I am able to clone and append it to the parent, but I want to know how I can replace certain tags inside. </p>

<p>to be specific here is the jquery i use to clone the target control</p>

<pre><code>var x =  $(parent).children('div[class="answer"]:first').children('div[class="ansitem"]:first').clone();
</code></pre>

<p>the html content inside the clone div is like this :</p>

<pre><code>&lt;div id="ansthumb_anstext_anscontrols"&gt;
    &lt;div id="image" class="ansthumb"&gt;
        replace 1
    &lt;/div&gt;

&lt;div id="atext" class="anstext"&gt;
    &lt;p class="atext_para"&gt;
        &lt;span id="mainwrapper_QRep_ARep_0_UName_0" style="color: rgb(51, 102, 255); font-weight: bold;"&gt;Replace 2 &lt;/span&gt;
        Replace 3
    &lt;/p&gt;

    &lt;p id="answercontrols"&gt;
        &lt;input name="ctl00$mainwrapper$QRep$ctl01$ARep$ctl01$AnsID" id="mainwrapper_QRep_ARep_0_AnsID_0" value='replace 4' type="hidden"&gt;
        &lt;a id="mainwrapper_QRep_ARep_0_Like_0" title="Like this answer" href="#"&gt;Like&lt;/a&gt;
        &lt;a id="mainwrapper_QRep_ARep_0_Report_0" title="Report question" href="#"&gt;Report&lt;/a&gt;
        &lt;span id="mainwrapper_QRep_ARep_0_lblDatetime_0" class="date"&gt;  replace 5 &lt;/span&gt;
    &lt;/p&gt;
&lt;/div&gt;
</code></pre>

<p> </p>

<p>here i have marked all the areas I want to be replaced. The id's of the above div elements are named as such because it is generated within a repeater control. </p>

<p>I have gone through the jquery API and this function seems to be the thing I should be using as far as i understand.</p>

<p>replaceWith(content)</p>

<p>but the drawback of this way is i have to dump  the entire html on to a string variable and include replacement text wherever needed. I think it is not the best way, and may be something like selecting particular tags and changing data would be the way to do it. Any help appreicated guys! </p>

<p>thanks</p>
