bunnyali2013 Posted October 30, 2012 Share Posted October 30, 2012 (edited) 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: $(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! Edited October 30, 2012 by bunnyali2013 Quote Link to comment https://forums.phpfreaks.com/topic/270091-jquery-check-if-objects-are-hidden/ Share on other sites More sharing options...
kicken Posted October 30, 2012 Share Posted October 30, 2012 I would guess that .is(':hidden') is not true until the hide animation is complete. What you would need to do is run a function after the animation ends (using it's callback parameter) that will run your :hidden tests. Quote Link to comment https://forums.phpfreaks.com/topic/270091-jquery-check-if-objects-are-hidden/#findComment-1388851 Share on other sites More sharing options...
bunnyali2013 Posted October 30, 2012 Author Share Posted October 30, 2012 I did this, I want it like this, but the alert box is not appearing.. http://jsfiddle.net/angelali2013/TAmNX/1/ Quote Link to comment https://forums.phpfreaks.com/topic/270091-jquery-check-if-objects-are-hidden/#findComment-1388856 Share on other sites More sharing options...
kicken Posted October 30, 2012 Share Posted October 30, 2012 .is() returns true or false based on whether the elements match the given selector. If any of the images you selected are visible it will return true, if they are all hidden it will return false. That false is what you need to check for, not a non-existant .length property. if (!$('#image1, #image2, #image3, #image4').is(':visible')) { alert('I am a bunny'); } Quote Link to comment https://forums.phpfreaks.com/topic/270091-jquery-check-if-objects-are-hidden/#findComment-1388864 Share on other sites More sharing options...
bunnyali2013 Posted October 31, 2012 Author Share Posted October 31, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/270091-jquery-check-if-objects-are-hidden/#findComment-1388940 Share on other sites More sharing options...
bunnyali2013 Posted October 31, 2012 Author Share Posted October 31, 2012 well i think it is working now..thank you if i get some issues, i will come back later... Quote Link to comment https://forums.phpfreaks.com/topic/270091-jquery-check-if-objects-are-hidden/#findComment-1388941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.