JQuery: How to loop through all child elements of a div
<p>I am trying to loop through all elements in a given div and output the results (C# code i will use later) to the screen for testing.</p>

<p>so if i have html like this:</p>

<pre><code>    &lt;div id="testDiv"&gt;
        &lt;test&gt;
            &lt;a&gt;aVal&lt;/a&gt;
            &lt;c&gt;
                &lt;cc&gt;ccVal&lt;/cc&gt;
            &lt;/c&gt;
       &lt;/test&gt;
    &lt;/div&gt;
</code></pre>

<p>i am trying to produce this string value:</p>

<pre><code>HtmlElement.CreateNode("test").AddNode(CreateNode("a").addText("aVal")).AddNode(CreateNode("c").AddNode(CreateNode("cc").addText("ccVal"))
</code></pre>

<p>Right now i ahve this jquery in place, but i am unsure of how to drill down into the other nodes:</p>

<pre><code>var x = "HtmlElement.";
$('div#testDiv').children().each(function () {    
    var nodeNameStr = this.nodeName.toLowerCase();
    var nodeText = $(this).text();
    x += "CreateNode(nodeNameStr).addText(nodeText)"
});
</code></pre>
