jQuery changing the id attribute of all the children
<p>I need some help figuring out how to write some jQuery code.</p>

<p>I need to clone a table dynamically onclick. but then I need to change the ids of the table and its child elements each time. as the table can have lots of children it will be to difficult to do this manually. I need a way to change the id's of all child(all descendants) elements. I will always just add the counter to the id. (I know children will access only the immediate children but I just wanted to try if that works). If you guys know how this can be done in either jQuery or Javascript, please let me know.</p>

<pre><code>&lt;table id="table"&gt; 
    &lt;tr id = "tr" &gt; 
        &lt;td id="td"&gt; 
            &lt;span id="span" value="hiii"&gt;hi&lt;/span&gt; 
        &lt;/td&gt; 
    &lt;/tr&gt;
&lt;/table&gt; 

&lt;button&gt;Clone&lt;/button&gt; 

&lt;script&gt; 
    $("button").click(function () { 
        var table = $("#table").clone(true,true) 
        table.attr( 'id', function() { return this.id +"1"; })    
        alert($("#table1").children()) 
        $("#table1").find(*).attr('id', function() { return this.id +"1"; }) 
        table.appendTo("#table") 
        alert(document.getElementById("tr1")) 
        alert(document.getElementById("span1").value) 
    }); 
&lt;/script&gt;
</code></pre>
