Test condition for visibility check in JavaScript
I'd like to know if there's a test conditions using which one can check 开发者_C百科the visibility state(hidden or visible) of a tag.
I mean a test condition,which could be used with the if() statement.
thanks!
if you are using jQuery then:
$('#id').is(':visible');
In case you don't use jQuery this simple javascript condition should work:
if(document.getElementById("elementId").style.visibility=="visible"){
    // do something
}
Simple solution is to use jQuery and do $('#id').is(':visible'). Otherwise you'll be writing a function that doesn't work as well and isn't as nicely coded.
If you use jQuery, it's very easy:
if ($(SELECTOR).is(":visible")) {
  // do amazing things
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论