Amount of elements can not be evaluated?

Amount of elements can not be evaluated?

Hi all

I have a serious problem and I need your help.

I got from AJAX back the following Labels "Software Engineering", "Infomatics", "Software Architecture". Now, I put these elements into an "input" (called characteristic) and add after every "input" I put a checkbox (called characteristicsYesNo) . These is the code for that:

  1. function(data){       
                                                   for(var i = 0, cnt = data.Characteristics.length; i < cnt; i+=1)  {
                                                      $('<input readonly="readonly" id="characteristic'+ i +'" name="characteristics{{loop.index0}}'+ i +'"  value="' + data.Characteristics[i] + '" />').appendTo('tr[id=elem4{{loop.index0}}]')
                                                      $('<input type="checkbox" id="characteristicYesNo{{loop.index0}}'+ i +'" name="characteristicsYesNo{{loop.index0}}'+ i +'" value="" />').appendTo('tr[id=elem4{{loop.index0}}]')  
                                                      console.log('characteristicYesNo'+ i)
                                                   }
                                               },
                                            "json"); 






This works fine, but after that I press the "Save" button I want to build up a for loop, and for that I have to count the "input" fields first and I always get back a 0. This is the code with which I want to do that:

  1.    $("#speichern_education{{loop.index0}}").click(function () {
                                            var a = $("#characteristic").length;
                                            var b = $("#characteristic").size();


  2.                                           console.log(a);
  3.                                           console.log(b);
  4. ...
The result should be 3, but is 0 instead. :-(  What is wrong with my code? Thank you for your help.

If you need something more I can post it, but the whole code is huge.

Cheers Roger