views:

39

answers:

2

I have an array of classes and IDs and am trying to iterate through and append to those elements. The code below works in all browsers apart from IE7 and below. IE7 and below throw an exception telling me that 'length' is null or undefined. Been wrestling with it for a while now. Any ideas?

Code is here: http://gist.github.com/651456

A: 

try

$(element).size()
Mark Baijens
.length is part of the jQuery API. It returns the number of elements in jQuery object, the same value as .size(). see: http://api.jquery.com/length/
Fermin
my mistake, ur right.
Mark Baijens
A: 

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.

awayken