Replacing the contents of tag with another tag using Java script
<p>I want to replace the value of the tag  </p>

<pre><code>&lt;h2&gt;..&lt;/h2&gt;
</code></pre>

<p>with the content of the tag</p>

<pre><code>&lt;h3&gt;..&lt;h3&gt;
</code></pre>

<p>I wrote the script like this, </p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;div&gt;
            &lt;h3&gt;&lt;span&gt;&lt;!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:addwidget[1]/custom:text[1]"} --&gt;
                        &lt;strong&gt;Section Text&lt;/strong&gt;
                    &lt;/span&gt; &lt;/h3&gt;

                &lt;h2&gt;
                        &lt;a title="Google" href="http://google.com"&gt;google.com&lt;/a&gt;
                    &lt;/h2&gt;
            &lt;/div&gt;  

        &lt;script type="text/javascript"&gt;
        var x=document.getElementsByTagName("div");

        for (var i=0; i&lt;x.length; i++) {
        var children = x[i].getElementsByTagName('h2');

        var demo= children["demo"].innerHTML;


        var childd =x[i].getElementsByTagName('h3');

        var all=childd["all"].innerHTML;



        children["demo"].childNodes[0].innerHTML=all;
        childd["all"].innerHTML=null;
        }

        &lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt; 
</code></pre>

<p>Rule:</p>

<p>In the above example I want to replace "google.com" with the text in the <code>&lt;h3&gt;</code> tag.
But I am not getting the output.</p>

<p>Output needed.</p>

<pre><code>    &lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;div&gt;

                &lt;h2&gt;
                        &lt;a title="Google" href="http://google.com"&gt;
                        &lt;span&gt;&lt;!-- Start Component Field: {"XPath":"tcm:Content/custom:Content/custom:addwidget[1]/custom:text[1]"} --&gt;
                            &lt;strong&gt;Section Text&lt;/strong&gt;
                        &lt;/span&gt; 
                        &lt;/a&gt;
                    &lt;/h2&gt;
            &lt;/div&gt;  


&lt;/body&gt;
&lt;/html&gt; 
</code></pre>

<p>I am not getting the exact output.
I have used for loop because I want to do it for every occurrence of div tag.</p>

<p>Can any one look into it and suggest how to correct it.</p>

<p>Thanks.</p>
