title: Onclick dynamically added with javascript to td element doesn't work
body: <p>I have a problem trying to figure out why my dynamically added onclick event doesn't do anything. I have searched many sites already but nothing I tried worked. Knowing myself it is probably some kind of stupid mistake but I really want to know what I did wrong. This is a part of my code including relevant functions:</p>
  
  <pre><code>        function ChangeNumber(line){   //this is just a test function so far :)
              document.getElementById('maincol').innerHTML += line + "&lt;br/&gt;"; //just adds "something to the end of a div"
          }
  
          function ChangeSize()
          {
              var rows, cols;
              rows = document.getElementById('rows').value;
              cols = document.getElementById('cols').value;
  
              var tbody = document.getElementById('model');
              tbody.innerHTML = "";
  
              for (var i = 0; i &lt; rows; i++){
                  var tr = document.createElement('tr');
                  for (var j = 0; j &lt; cols; j++){
                      var td = document.createElement('td');
                      td.setAttribute('name', (i * cols) + (j + 1));
                      td.onclick = function() {ChangeNumber('something'); };
                      td.innerHTML = "0";
                      tr.appendChild(td);
                  }
                  tbody.appendChild(tr);
              }
  
          }
  </code></pre>
  
  <p>The creation of the table works fine and so does call to the function <code>ChangeNumber()</code> from statically created onclick but when I click on the dynamically created td nothing happens. Can someone please clarify the problem to me?</p>