Page 1 of 1

Need help using the ID's value as a variable

Posted: Wed Mar 23, 2011 8:56 pm
by vic3685
Hi guys!

I've been struggling with a piece of code. I'm guessing the solution is quite simple, but I just can't find it!!!

Here's the piece of code:

$('.i_gal').click(
function(){
$('#gal1').removeClass('gal_hide').addClass('gal_show');
document.getElementById('fade').style.display='block';
/* var exact_img= this.attr('id');*/
galleries[0].showImage(5 );
}
);

This code should load an image gallery, and the number in purple is the number of the picture that should be opened when I click one of the thumbnails.

The thumbnails are structured as follows (it's a php loop):

<img src='".$row['folder']."thumbs/".$row['filename']."' height='46' class='i_gal' id='".$num."'><span>Menu</span>

The line that I commented out was an attempt at getting a variable that had the value of the image-id, but it doesn't work. Could you help me? I just need to replace that 5 is with a variable.

Re: Need help using the ID's value as a variable

Posted: Thu Mar 24, 2011 5:33 am
by vishal_arora
<html>
<head>

<script src="jquery-1.5.js"></script>
</head>
<body>

<img src='test.jpg' height='46' class='i_gal' id='2'><span>Menu</span>

<script>

$(".i_gal").click(function () {
alert(this.id)
});

</script>

</body>
</html>

Try this its working