Jakob
Jakob

Reputation: 143

Jquery works in every browser other than IE

For IE this code worked and I did the IE comment that only IE can read..

<!--[if gt IE 6]>
<script type="text/javascript" 
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
{

    //--my code
    $(document).ready(function() 
    {
        $('.thumbnail').live("click", function() 
        {
            $('#mainImage').hide();
            $('#imageWrap').css('background-image', "url('ajax-loader.gif')");
            var i = $('<img />').attr('src',this.href).load(function() 
            {
                $('#mainImage').attr('src', i.attr('src'));
                $('#imageWrap').css('background-image', 'none');
                $('#mainImage').fadeIn();
            });
            return false; 
        });
    });
};


</script> <![endif]-->

For Every other browser this code worked...

<script type="text/javascript">
$(document).ready(function() {
    $('.thumbnail').live("click", function() {
        $('#mainImage').hide();
        $('#imageWrap').css('background-image', "url('ajax-loader.gif')");
        var i = $('<img />').attr('src',this.href).load(function() {
            $('#mainImage').attr('src', i.attr('src'));
            $('#imageWrap').css('background-image', 'none');
            $('#mainImage').fadeIn();
        });
        return false; 
    });
});


</script>

I got the working code, even though they each do something different, they do what I need them to do. The only thing is IE doesn't want to read the code to do what I need... What am I missing? Thanks in advance!

Upvotes: 0

Views: 157

Answers (3)

ContextSwitch
ContextSwitch

Reputation: 2837

Are the opening and closing braces on the outside of your document.ready() part of you code?

Remove the first

{

and also the last

};

You don't need to wrap everything in braces.

Upvotes: 1

Kevin B
Kevin B

Reputation: 95056

Swap these two around:

$('<img />').attr('src',this.href).load(function()

should be

$('<img />').load(function(){...}).attr('src',this.href)...

so that it will work in IE6-IE8 once the image is cached.

Reference to this answer: Check if dynamically loaded images are complete

Upvotes: 0

Mathew Thompson
Mathew Thompson

Reputation: 56459

You've got too many closing braces in your IE6 version, see here:

});
}; <- delete me

Remove the }; and you should be good :)

Edit: You've also got a rogue { at the start too, get rid of that as well, it's here:

{ <- delete that!

//--my code
$(document).ready(function() 
{

Upvotes: 4

Related Questions