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 530719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:13:35+00:00 2026-05-13T09:13:35+00:00

I have a (php/html/jquery/css) page where i’m displaying tags at the top (e.g. green,

  • 0

I have a (php/html/jquery/css) page where i’m displaying tags at the top (e.g. green, white, fruit, vegetable)

On the page I have divs marked appropriately with classes:

<div class="green fruit">apple</div>
<div class="green vegetable">broccoli</div>

etc.

I’d like to show/hide divs based on which tags have been toggled show/hide.

By default everything is shown. Clicking a tag at the top will toggle the corresponding divs.

The tricky part is to show divs if any of its classes are toggled to ‘show’ and hide if all of its classes are toggled to hide.

I’m probably making this harder than it needs to be. Thanks for your advice!

  • 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-13T09:13:35+00:00Added an answer on May 13, 2026 at 9:13 am

    Assuming that you’re using buttons to toggle the tags:

    <button class="tag" id="toggle-fruit">Fruit</button>
    <button class="tag" id="toggle-green">Fruit</button>
    <button class="tag" id="toggle-vegetable">Fruit</button>
    ...
    

    This should work:

    var divCollection = $('div'),
    
        // Gather all tags (store in array):
        tags = $.map(divCollection, function(){
            return this.className.split(' ');  
        }),
    
        // Object to store enabled tags:
        enabledTags = {};
    
    toggleTags();
    
    $('button.tag').click(function(){
    
        var tag = this.id.split('-')[1];
    
        enabledTags[tag] = !enabledTags[tag];
    
        $(this).toggleClass('toggled'); // Maybe add some CSS?
    
        toggleTags();
    
    });
    
    function toggleTags() {
    
        // Hide all divs, then show those that have at least one
        // tag present in the enabledTags object.
        divCollection.hide().filter(function(){
    
            // Return true if one of classes is found in enabledTags
            return !!$.grep(this.className.split(' '), function(){
                return enabledTags[this];
            }).length;
    
        }).show();
    }
    

    See demo: http://jsbin.com/omota

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

Sidebar

Related Questions

I have a problem in integrating PHP and JQuery: My main file is MyFile.html
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have to deploy my php/html/css/etc code to multiple servers and i am looking
Basically Im attempting to take a php / jquery / css / html web
I have the following jQuery function: $(function(){ if ($(.menu li).hasClass(active)) { $(.active).css(margin-top, 6px); }
I have a website which uses PHP and HTML pages, I want to create
I have an HTML form - with PHP, I am sending the data of
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
I have a javascript function defined somewhere in the middle of my html/php based
I have PHP configured so that magic quotes are on and register globals are

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.