Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery if visible

Tags:

jquery

 <div id="chatCenterMembers">
   <div class="chatmember">
       <a title="Blah Blah Blah">
          <div class="newchatmessage" style="display: block;"></div>

How can I capture the visible div in an if statement?

I have $(this) set to <div class="chatmember"> - second line from the top.

I've been working with below but had now luck so far.

if($(this+' a div.newchatmessage').filter(":visible")) {

Above just drops out...

I've also tried below and it doesn't work either

if ($(this + 'a div.newchatmessage').is(':visible')) {
like image 766
Adam Avatar asked Aug 18 '11 07:08

Adam


1 Answers

Use .is() to check if an element fills a certain requirement, like such:

if ($(this).find('a div.newchatmessage').is(':visible'))

Or, if you want it more readable:

var element = $(this).find('a div.newchatmessage');

if (element.is(':visible')) {
    // Do your thing
}
like image 53
Joakim Johansson Avatar answered Oct 15 '22 17:10

Joakim Johansson