Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-30-2012, 10:00 PM   PM User | #1
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
JQuery check if objects are hidden

Hello, I have an issue. I have 10 images in a div. The images' names are in a second div. So, there are 10 images and 10 names.

When a user will click on an image, it will hide as well as its respective name. So, if the user clicks on the second image, it will hide as well as its name until everything is hidden.

Once the user has clicked all images, an alert box will appear. Refer to the code now for a single image:

Code:
$(document).ready (function() {
$("#image").click(function() {
$("#image, #name").hide("slow");
if ($("#image").is(":hidden")) {
alert("Ok");
};
});
});
As you see, when the user will click an image, it will hide as well as well the name. This goes the same for all images. The alert box will be displayed once the image is hidden else not, so I have to verify if the image is hidden. I could give them a single class instead of an ID, but the user can click only on the image div. Bear in mind, the above example is just for one image only. I have 10 images, but decided to include example for one in general to make you understand. The image and the name are hiding, but the alert box is not displayed!
angelali is offline   Reply With Quote
Old 10-30-2012, 11:11 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Welcome to the world of asynchronous methods

The hide("slow") will slowly hide the image while(!) the following if statement is already executed and at that point of time the image is not yet :hidden

Asynchronous methods usually provide a means to specify a so called "callback" which is a function that will be called as soon as the asynchronous method finished executing.

Code:
$("#image, #name").hide("slow", function() {
   // now #image and #name are hidden!
   alert('ok');
});
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
angelali (10-31-2012)
Old 10-30-2012, 11:14 PM   PM User | #3
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
I did this, I want it like this, but the alert box is not appearing..

http://jsfiddle.net/angelali2013/TAmNX/1/
angelali is offline   Reply With Quote
Old 10-30-2012, 11:31 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Code:
if ($('#image1:visible, #image2:visible, #image3:visible, #image4:visible').length == 0) {
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
angelali (10-31-2012)
Old 10-31-2012, 08:12 AM   PM User | #5
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Thank you for responding, but it is executing two alert boxes after hiding. I want that when all images are hidden, then it executes the alert box, and of course only one time..
angelali is offline   Reply With Quote
Old 10-31-2012, 08:37 AM   PM User | #6
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
It seems it is working now, I change 'is' to filter. Thank you. if i get issues, i will come back later.
angelali is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:41 AM.


Advertisement
Log in to turn off these ads.