0

I have the below code on a html5 document but it is not working in IE. It works OK in Chrome but ive read that IE is not so forgiving on scripts and the way they are coded.

I am very new to jQuery so any help would be appreciated thanks.

<div class="gallery">

    <div id='gallery-1' class='gallery galleryid-6 gallery-columns-9 gallery-size-thumbnail'>
        <dl class='gallery-item'>
            <dt class='gallery-icon'>
                <a href='http://mysite.co.uk/homepage-01.jpg'><img src="http://mysite.co.uk/01-90x90.jpg" /></a>
            </dt>
        </dl>
        <dl class='gallery-item'>
            <dt class='gallery-icon'>
                <a href='http://mysite.co.uk/homepage-02.jpg'><img src="http://mysite.co.uk/02-90x90.jpg" /></a>
            </dt>
        </dl>
        <dl class='gallery-item'>
            <dt class='gallery-icon'>
                <a href='http://mysite.co.uk/homepage-03.jpg'><img src="http://mysite.co.uk/03-90x90.jpg" /></a>
            </dt>
        </dl>
    </div>

</div><!--gallery-->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<script>
    $(document).ready(function () {
        $("div.gallery a").click(function () {
            event.preventDefault();
            $("div.picture").html($("<img>").attr("src", this.href).fadeIn(1000));
        });
    });
</script>
2
  • What does "it is not working" mean? People on Stackoverflow don't like to guess at these things. Commented Feb 28, 2013 at 0:44
  • your right sorry, will bare that in mind in future. It was images showing as thumbnails in one div (.gallery) were linked to their larger image. And the linked larger image should show in another div (.picture) on the page Commented Feb 28, 2013 at 1:23

2 Answers 2

4

The variable event isn't defined it should be:

$("div.gallery a").click(function (event) {
    event.preventDefault();
    $("div.picture").html($("<img>").attr("src", this.href).fadeIn(1000));
});
Sign up to request clarification or add additional context in comments.

Comments

0

You need to "pass" the event to your click handler:

$("div.gallery a").click(function(event) {    // <---- here
        event.preventDefault();

...otherwise event is undefined within the click handler. Referencing it will cause things to break (I'm surprised it works anywhere).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.