Need help using the ID's value as a variable

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
vic3685
Forum Newbie
Posts: 5
Joined: Thu Mar 17, 2011 7:32 pm

Need help using the ID's value as a variable

Post 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.
vishal_arora
Forum Newbie
Posts: 8
Joined: Thu Mar 24, 2011 5:08 am

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

Post 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
Post Reply