Matchew
Matchew

Reputation: 23

jquery click event.. Do I need an each loop?

I have this code within a Wordpress template is used within an image gallery, so each image, when clicked shows a pop up which can be clicked on to go to a contact page about that product.

$("#cycle div.i").click(function () {// show pohelp 
    $('quickinfo').hide();
    var quickinfo = '#'+ $(this).find('a').attr('rel');
    var offset = $(this).offset();
    $(quickinfo).css('left', parseInt(offset.left-90)+'px').css('top', parseInt(offset.top-205)+'px').removeClass('l j hideme');
});

The issue is that the image that has shown up will not remove when another image is clicked. I would like only one popped up more info image to show at once.

Upvotes: 0

Views: 100

Answers (1)

user2610222
user2610222

Reputation:

$('quickinfo').hide(); is not working as it selects an invalid element.

You just add class to all the images. For instance, add a class "image_gallery" like so:

<img class="image_gallery">
<img class="image_gallery">

Then use that class to select them as $('.image_gallery).hide() instead of your invalid $('quickinfo').hide();

$("#cycle div.i").click(function () {
    $('image_gallery').hide();
    var quickinfo = '#'+ $(this).find('a').attr('rel');
    var offset = $(this).offset();
    $(quickinfo).css('left', parseInt(offset.left-90)+'px').css('top', parseInt(offset.top-205)+'px').removeClass('l j hideme');
});

Upvotes: 2

Related Questions