According to jQuery's API, .length should work just the same as .size(), so I don't think that's the issue. I think the problem might be in how you're using the jQuery.each() method. Again, according to the API, the jQuery.each() callback passes in two values: indexInArray (which you use as index) and valueOfElement (which you use as element). The problem might be with IE7 being unable to turn your valueOfElement into a jQuery object, and thus it can't get the .length property of it.
I'm not familiar with Drupal code, so I haven't tested this, but I think this line:
if ($(element).length) {
could be rewritten as this:
if ($(element) && $(element).length) {
to fix your issue.
I apologize for not being able to test this first, but I hope it works.