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

  • SEARCH
  • Home
  • 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 7783853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:57:50+00:00 2026-06-01T19:57:50+00:00

Hello i want to count all visible div Elements with the value form the

  • 0

Hello i want to count all visible div Elements with the value form the list item.
Items witch are hidden have count 0
If i do the count by hand (item by item) it works, here my example:

 var counter = $(".green").length-$(".green.hidden").length;

Here is my page how i want to use it:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery-1.7.1.min.js">
</script>
<style>
  a {text-decoration: none; }
  div { border:1px solid grey; width:200px; height: 10px; margin:3px; }
  .black { background-color:black; }
  .blue { background-color:blue; }
  .green { background-color:green; }
  .hidden { visibility:hidden; }
</style>
</head>
<body>
<ul id="list1"> 
  <li><a href="" value="">all<span></span></a></li>
  <li><a href="" value=".black">black<span></span></a></li>
  <li><a href="" value=".blue">blue<span></span></a></li>
  <li><a href="" value=".green">green<span></span></a></li>
</ul>
<div class="element black"></div>
<div class="element green hidden"></div>
<div class="element blue"></div>
<div class="element green "></div>
<script>
$(function(){
 var totalcount = 0;
 var counter = 0;
$("li a").each(function(){
 var counter = $(this).attr("value").length;
 var totalcount = totalcount+counter;

   $(this).find("span").html(" (" + counter + ") ");
});
   $("span", 'a[value|=""]').html(" (" + totalcount + ")");
});
</script>
</body>
</html>

The List have to look like this:
All (3)
black (1)
blue (1)
green (1)

Thanks in forward

  • 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-06-01T19:57:51+00:00Added an answer on June 1, 2026 at 7:57 pm

    An <a> element has no attribute value, to count elements with classes that are visible do:

    var all = $('.element').filter(":visible").length,
        green = $('.green:visible').length,
    
    ....etc
    

    Note that elements that are just ‘visibility:hidden” are considered visible, and this will not work on such elements.

    Here’s how I would do it:

    HTML:

    <ul id="list1"> 
      <li><a href="#" data-color="all">all<span></span></a></li>
      <li><a href="#" data-color="black">black<span></span></a></li>
      <li><a href="#" data-color="blue">blue<span></span></a></li>
      <li><a href="#" data-color="green">green<span></span></a></li>
    </ul>
    <div class="element black"></div>
    <div class="element green hidden"></div>
    <div class="element blue"></div>
    <div class="element green "></div>
    

    jQuery:

    $(function(){
        $.each($('li a'), function(index, item) {
            if ($(item).data('color')=='all') {
                $('span', item).text(' ('+$('.element:visible').length+')');
            }else{
                $('span', item).text(' ('+$('.'+$(item).data('color')+':visible').length+')');
            }
        });
    });​
    

    FIDDLE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have set of elements. They have several classes on one element. <div
Hello i want to replace the text in div when user click on it
I have: %{ lorem ipsum dolor sit %{hello world}% amet}% I want: hello world
Hello friends i want to add more effects on my div when i click
Hello Sir i want send list of data to php server i use following
I want to compute and count all trigrams of a string in SQL Server.
I am parsing XML using jQuery. I want to get the count of all
Hello you all How can i get row count of ObjectDataSouce ? I use
Hello and good day to all. I have an issue on coding, i have
I want to get all comments count grouped by category. eg f1 f2 f3

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.