0

Hi I would like to detect whether an element is visible or hidden. I thought about this

$("#mobile_navbar:visible").change(function() {
   console.log("detected")
});

but this does not seem to work...? Any ideas how to do this? Basically I what to check whether $("#mobile_navbar").is( ":visible" ) has changed... but I want that a function is called whenever that happens, lick the .click() function which gets triggered if an element is clicked on.
thanks carl

carl
  • 3,322
  • 6
  • 32
  • 80

2 Answers2

0
var isVisible = $("#mobile_navbar").css('display');
if(isVisible != 'none') {
   console.log("detected")
};
chetank
  • 394
  • 3
  • 13
0

If you want to check that the element is visible on the screen, you can do like this :

if($(selector).css('visibility') == 'hidden') {
   doSomething
}
else{
  doSomethingElse
}
digode
  • 167
  • 9