I’m trying to write some javascript to ensure that a table has lineNumber tr elements of a specific class inside it. I have the following loop to do so:
while ($(".functionCodeLine").size() < lineNumber) {
console.log($(".functionCodeLine").size());
funcLineRow = $('<tr class="functionCodeLine"></tr>');
table.append(funcLineRow);
...
}
But in my log statement I see that the returned size is always 0. If I inspect the DOM I see that new tr’s are being added with the class attribute. So I’m at a little of a loss to understand why size is always 0 and the loop never terminates. What am I missing?
So I’m not really sure what the issue is in the above code, but I was able to work around it with: