Thursday, November 26, 2009

Re: [jQuery] IE balking at .siblings() - says 'Object does not support this property or method'

The first thing that caught my eye looking at your code is the missing "var" on this line:

               lg_pic = $(this).siblings('.lg_pic_name').html();

Surely you don't want to be creating a global variable here? It should be:

               var lg_pic = $(this).siblings('.lg_pic_name').html();

It's even possible that this will fix your problem. Do you have an element in your page with id="lg_pic"? If so, this will fix it.

For every element ID in your page, IE creates a *read-only* property on the window object with that name. So if you have an element with id="lg_pic", then there is a window.lg_pic property that is read-only. When you try to store a value into that property it will fail.

If that doesn't turn out to be it, can you please post a link to a test page? It's awfully hard to troubleshoot a code snippet without seeing the actual error in a live running page.

-Mike

On Thu, Nov 26, 2009 at 12:47 PM, Getzel <fardak@gmail.com> wrote:
BH

I created a slider of thumbnail images. I write the image filepaths
directly into the HTML using PHP, so instead of using expandos I
placed a hidden div after each image containing the file name of the
large version to be shown onclick. Works fine in FF and Chrome. IE
stops at the first line in the function, at .siblings(). It throws an
error saying 'Object does not support this property or method.'

$('.pic_listing img').click(function(){
               // Set the a variable with large image associated with
the thumb
               lg_pic = $(this).siblings('.lg_pic_name').html();

               // If it is not currently displayed
               if($('#lg_pic_src').attr('src') != path+lg_pic){
                       //Hide Old Image
                       $('#lg_pic_src').css('display','none');
                       //Replace it
                       $('#lg_pic_src').attr('src',path+lg_pic);
                       // Display Loader img
                       $('#loader').css('z-index',1);
                       // Once its loaded, Hide Loader and FadeIn the
new image
                           $('#lg_pic_src').load(function () {
                                       $('#loader').css('z-index',-1);
                                       $('#lg_pic_src').fadeIn();
                           });
               }
});

Anyone have any thoughts as to why IE would throw an error?
Other functions defined in the same file work fine.

Thanks,
Getzel

No comments: