0

Is it possible to do a callback for the below?

$('.element').css("visibility","visible");

I came across this but seems like there are issues using this in chrome.

$('.element').css("visibility","visible").promise().done(function(){
    alert( 'done! start stuff...' );
});

Basically I'm looking for a way to confirm that the $('.element') is visible before proceeding to the next line.

Becky
  • 5,467
  • 9
  • 40
  • 73

2 Answers2

1

Setting an element to be visible is synchronous so there is no reason or purpose to using a promise with that. There is nothing to wait for that to take effect.

$('.element').css("visibility","visible");
console.log($('.element').css("visibility"));   // will show "visible" immediately

If, on the other hand, you want to wait for a repaint so the item is actually drawn on the screen, that is a different story. You will have to either force a repaint (which is a tricky non-standard thing to do in browsers these days as they try to avoid synchronous repaints) or you will have to use a slight delay with setTimeout() which allows a repaint to happen.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

For making an element visible, try display:block or display:inline-block (and a bunch of other display properties other than display:hidden).

Here is a difference between display and visibility properties.

Also, making an element visible doesn't guarantee that it is visible to user since it could be child of hidden parent element. You can use visible selector of jquery to confirm the same.

$('.element').css("display","block");

if ( $('.element').is( ":visible" )
{

} 
Community
  • 1
  • 1
gurvinder372
  • 66,980
  • 10
  • 72
  • 94