Using a variable in a eq() custom selector index

Using a variable in a eq() custom selector index

I want to be able to get the index number of the image I'm clicking on and use this reference to show another image.

To see if it worked in principle I used:

$(".thumbnail").click(function () {

     $('.thumbnail').hide(); //class of the image clicked on

     $('.popUp:eq(5)').show();

    });

This worked fine, popping up the 6th image with class "popUp"

I then tried to get the index number of the image I clicked on to use as a parameter for the index of the image I wanted to pop up

$(".thumbnail").click(function () {

       var ind ;

     ind = $(this).index();

     $('.thumbnail').hide();

     $('.popUp:eq(ind)').show();

    });


This didn't get my image to popUp, so I tried to simplify it to get at the problem


$(".thumbnail").click(function () {

       var ind ;

     ind = 5;

     $('.thumbnail').hide();

     $('.popUp:eq(ind)').show();

    });

This also didn't work and I can't see why. It works when I use eq(5) but not when I use a variable ind = 5 as the parameter: eq(ind)

Grateful for any help.