2

The code below can checks if the image is visible or not.

$('#div1 img:visible')

Which selects all image descendants and:

$('#div1 > img:visible')

I just need to know that when I iterate over every image in a container like dgImages $("#dgImages] img").each(function () {} how I can determine that the image is visible or not ? Can I write something like if($(this:visible)){//Do something}?. Thanks.

Derk Arts
  • 3,432
  • 2
  • 18
  • 36
Keith Costa
  • 1,783
  • 11
  • 35
  • 68

4 Answers4

5

You can use is() to check your object against any selector:

if($(this).is(':visible')) { ... }
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
5
$("#dgImages").find('img').each(function(){
   if($(this).is(':visible')){
     alert("This image is visible");
    }
});
dku.rajkumar
  • 18,414
  • 7
  • 41
  • 58
4

You can use .is():

if ($(this).is(':visible')) {
  ...
Blender
  • 289,723
  • 53
  • 439
  • 496
1

This page demonstrates an alternative approach using display: http://acarna.com/vis-test.php

Rather than looking at every single image I've used a class to identify a specific group of images that need to be toggled. Clicking the 'Toggle' button tests .css("display") to get the current display state and toggle it to inline or none accordingly.

View the source on the above page for more details.

If you have Firebug installed you can watch what happens to the markup as the display property is toggled between inline and none.

user8109
  • 768
  • 1
  • 5
  • 11