It:
$('.parent').children().length;
is the right way to do this. It:
$(this).children().each(function().length; // 1
is a syntax error. If you really want to iterate through children, you can use ".each ()", but you will need to do it correctly:
$(this).children().each(function() {
var $child = $(this);
});
Note that inside the callback, ".each ()" thiswill refer to each child element sequentially, since the function is called by jQuery.