2

So my container div when is not visible is this :

div id="content-wrapper" style="display: block; left: -980px; ">

and when is visible is this :

div id="content-wrapper" style="display: block; left:0px; ">

I want to append a div when a div container is visible, and I don't know how exactly to do this.

alexandru
  • 167
  • 2
  • 2
  • 11

2 Answers2

2

Is there any reason you're using a position instead of hiding the div? If you hid the div (style="display: none;") then you could use the :visible selector in jQuery. You could also use a class (class="hidden") then you could use jQuery to see:

if ($('#content-wrapper').hasClass('hidden'))
{
    // append div
}

Without that, you're pretty much dead in the water as you don't want to rely on spacing or text case.

Francis Lewis
  • 8,872
  • 9
  • 55
  • 65
0

$("#content-wrapper:visible") will return #content-wrapper when visible.

using the visible selector:

http://api.jquery.com/visible-selector/

So you could do something like $("#content-wrapper:visible").append(...)

Related to:

how to check image is visible or not?

Check if divs are visible with jQuery

How to determine if a table row is visible or not?

Community
  • 1
  • 1
wrschneider
  • 17,913
  • 16
  • 96
  • 176
  • 1
    I *think* "visibility" is being achieved by position `left: -980px;`, which the `:visible` selector wouldn't take into account. –  Dec 31 '11 at 01:45