jquery, IE7 and iteration
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 belo开发者_Python百科w 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
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.
try
$(element).size()
精彩评论