title: Working with getElementById( x ).onclick = someFunction
body: <p>I thought for long how to define the question but i couldn't, i need to explain the code.</p>
  
  <p>I want to make a simple organizer in JavaScript. You enter the task and click on the button "add to the list" and a script makes a checkbox with paragraph that contains the task's text. The second part is the disabling the checkbox, and striking through that tasks text when you click on it. I tried to do that by giving every checkbox i create a function (destroyIt() that gets element by id and than disables it, but it works only for the last checkbox added to the page. I am looking at this code for long time and i can't see what is wrong. Please help. Here is my code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
      &lt;style id="stil"&gt;
          .over{
              text-decoration:line-through;
          }
      &lt;/style&gt;
  
  
      &lt;script type="text/javascript"&gt;
          var numberOfTasks=1;
  
          function insertNew(){
              tekst = document.getElementById("zadatak").value;
              if(tekst.length&gt;0){
                  var idEl= "check"+numberOfTasks;
  
                  document.getElementById("ispis").innerHTML+="&lt;input type='checkbox' id='check"+numberOfTasks+"'&gt; "+"&lt;span class='"+idEl+"'&gt;"+tekst+"&lt;/span&gt; &lt;br/&gt;";
  
                  document.getElementById(idEl).onclick= function(){ destroyIt(idEl); };
  
                  numberOfTasks++;
              }
          }       
          function destroyIt(idEl){
              document.getElementById(idEl).disabled=true;
              document.getElementById("stil").innerHTML+= "."+idEl+"{text-decoration:line-through;}";
              alert(idEl+"{text-decoration:line-through;}");
          }
  
  
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      Tasks for: &lt;span id="date"&gt; &lt;/span&gt;
  
      &lt;script&gt;
          var date= new Date();
          document.getElementById("date").innerHTML= ""+ date.getDay() +"." +date.getMonth() +"." +date.getFullYear();
      &lt;/script&gt;
  
      &lt;br/&gt; &lt;br/&gt;
      New task: &lt;input type="text" id="zadatak"&gt; &lt;button onclick="insertNew()"&gt; add to the list &lt;/button&gt;
  
      &lt;button onclick="provera()"&gt;Provera&lt;/button&gt;
      &lt;p id="ispis"&gt; &lt;/p&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>