bind function to an element that created by javascript
<p>i want to create a calendar with javascript: </p>

<p>i'm create elements by this function:</p>

<pre><code>createElem : function (name, attrs){
     var el = document.createElement(name);
     for(var key in attrs) {
        el.setAttribute(key, attrs[key]);
     }
     return el;
}
</code></pre>

<p>table :</p>

<pre><code>var tb=this.createElem("table", {"class":"p-calendar", id: "p-calendar"});
</code></pre>

<p>rows and cells :</p>

<pre><code>for(var i=2; i&lt;to; i++){
    tb.insertRow(i);
    for(var j=0; j &lt; 7; j++){
       tb.rows[i].insertCell(j);
       .
       .
</code></pre>

<hr>

<p>so in my loop:</p>

<pre><code>tb.rows[i].cells[j].className="day"; // it's work
</code></pre>

<p>but :</p>

<pre><code>tb.rows[i].cells[j].onclick = function(){
    tb.rows[i].cells[j].id = "today";
}  // Unable to set property 'id' of undefined or null reference 
</code></pre>

<ol>
<li><strong>Why does the error?!</strong></li>
<li><strong>what is best way to bind function to an element that created by
javascript?</strong></li>
</ol>

<p>Thanks in advance.</p>
