how to assign a unique id to each checkbox
<pre><code>window.onload=function(){

 var container = document.getElementById('container'),
template = '&lt;li&gt;\
    &lt;input type="checkbox"&gt;\
&lt;/li&gt;\
&lt;li&gt;\
    &lt;input type="checkbox"&gt;\
&lt;/li&gt;\
&lt;li&gt;\
    &lt;input type="checkbox"&gt;\
&lt;/li&gt;';

container.onchange = function(e) {
var event = e || window.event,
    target = event.srcElement || event.target;

if( target.checked &amp;&amp; target.parentNode.getElementsByTagName('ul').length === 0 ) {
    var ul = document.createElement('ul');
    ul.innerHTML = template;
    target.parentNode.appendChild(ul);
} else {
    var ul = target.parentNode.getElementsByTagName('ul')[0];
    target.parentNode.removeChild(ul);
}
};

}

&lt;ul id="container"&gt;
&lt;li&gt;
    &lt;input type="checkbox"&gt;
&lt;/li&gt;
&lt;li&gt;
    &lt;input type="checkbox"&gt;
&lt;/li&gt;
&lt;li&gt;
</code></pre>

<p>how to assign unique id to every checkbox in the above code.................</p>

<pre><code>       &lt;input type="checkbox"&gt;
    &lt;/li&gt;
&lt;/ul&gt;
</code></pre>
