Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 802711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:38:52+00:00 2026-05-14T23:38:52+00:00

I need to do something only if all the li’s in a given ul

  • 0

I need to do something only if all the li’s in a given ul are hidden.. this doesn’t seem to do the trick. is there a way?

if ($('#some_ul li:hidden')) {
  // do something only if all 'li's in a given ul are hidden
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:38:53+00:00Added an answer on May 14, 2026 at 11:38 pm

    Check the length property of the elements returned.

    if ( !$('#some_ul li:visible').length ) {
      // do something only if all 'li's in a given ul are hidden
    }
    

    EDIT: changed hidden to visible


    EDIT: Clarification on the use of the .length property for a boolean test. Please see further explanation at the bottom of this answer.

    $('#some_ul li:visible').length returns the number of elements found. Numeric values equate to true or false.

    The ! gives you the negative of its true/false value.

    So if $('#some_ul li:visible').length find 0 visible elements, that is just the same as returning false.

    When you place ! behind it, it’s boolean value is reversed to true. So if no visible elements are found, the code in your if() will run.

    It is exactly the same as doing:

    if ( $('#some_ul li:visible').length == 0 ) {
      // do something only if all 'li's in a given ul are hidden
    }
    

    …which takes the numeric value of $('#some_ul li:visible').length and turns it into a boolean value using the == operator.


    To use :hidden you would need to first get the total length, then compare it to the hidden length.

    var total = $('#some_ul li');
    
    if ( $('#some_ul li:hidden').length == total ) {
      // do something only if all 'li's in a given ul are hidden
    }
    

    EDIT: In response to your comment, for clarification, there are several values that will equate to true/false in a test.

    Here are some examples of values that equate to false:

    var someVariable;  // someVariable is undefined, equates to false
    
    var someVariable = '';   // someVariable is an empty string, equates to false
    
    var someVariable = false; // someVariable is a boolean false, equates to false
    
    var someVariable = 0;  // someVariable is number zero, equates to false
    
    var someVariable = Number('a');  // someVariable is NaN (Not a Number), equates to false 
    
    var someVariable = null;   // someVariable is null, equates to false
    

    Here are some examples that equate to true:

    var someVariable = "false";   // someVariable is a string, equates to true
    
    var someVariable = 123;   // someVariable is a number greater than 0, equates to true
    
    var someVariable = -123;   // someVariable is a number less than 0, equates to true
    
    var someVariable = true;   // someVariable is a boolean true, equates to true
    
    var someVariable = !false;   // someVariable is a negated value that would
                                 //    otherwise be false, equates to true
    

    If you’re curious about the effective boolean value of any value, place !! before it.

    alert( !!123 );   // Alerts true
    

    The first ! converts the value to the opposite of its effective boolean value. The second ! converts the it back to its effective boolean value.

    For example:

    var a;  // an undefined variable
    
    alert( a );   // alerts undefined, logically equates to 'false'
    
    alert( !a );   // alerts the boolean opposite of undefined, which is 'true'
    
    alert( !!a );   // alerts the converts the boolean opposite 'true' back to 'false'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.