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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:49:45+00:00 2026-06-11T23:49:45+00:00

I have a set of span elements. I also have a set of <div>

  • 0

I have a set of span elements. I also have a set of <div> elements.
When I click on a span, I consider it as “disabled”. In particular, I store the “is disabled” property in an array (false for disabled, true otherwise); all the span elements are enabled at the beginning.

Each span has an integer id which comes from a DB value. I store this id in an HTML5 attribute named data-code.

Each div has a list of white-space separated integers. Each of these integers refer to the span’s data-code. They are stored in the div attribute data-lst.

The following is an example of a possible HTML code:

<span data-code="1">A text</span>|<span data-code="2">Another txt</span>|<span data-code="3">Some text here</span>|<span data-code="4">bla bla</span>

<div data-lst="1 2 3 4">...</div>
<div data-lst="1 3 4">...</div>
<div data-lst="2 3">...</div>
<div data-lst="1 2 3">...</div>
<div data-lst="1">...</div>

When I click on a span, it becomes “disabled” and I have to check if some div can be hidden (by using display:none). A div can be hidden if and only if each integer in data-lst corresponds to the id stored in data-code of a span that “is disabled”.
Some necessary examples:

  1. If I click on the span with data-code 1, then the last div is set to display:none.
  2. Then, If I click on span with data-code 3, nothing happens, since there is no div with all the codes in data-lst disabled (e.g. “1”, “3” or “1 3”).
  3. Finally, when I click on span with data-code 2, then the third and fourth span are set to display:none.

I’m trying to use selectors and JQuery to set display:none to the divs such that the criteria above are satisfied, but I didn’t found a solution at the moment.

A starting peace of code could be the following:

$(function(){
  var enabled = new Array();
  $('span').each(function(i){
    enabled[i] = true;
    $(this).click(function(){

      //Set display:none to all the divs that satisfy the above criteria 
      functionX();          

    });
  });
});

What is missing is functionX(), that should select all the divs corresponding to the criteria.

  • 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-11T23:49:46+00:00Added an answer on June 11, 2026 at 11:49 pm

    As per comments, Here is the updated jsfiddle and here is the updated code:

    $(function(){
        var enabled = {};
      $('span').each(function(){
          var $this = $(this);
          var id = $this.attr('data-code');
          enabled[id] = true;
          $this.click(function(){
              enabled[id] = false; 
              //Set display:none to all the divs that satisfy the above criteria 
              functionX(enabled);
          });
      });
    });
    
    function functionX(enabled)
    {
        $('div:visible').each(function() {
            var dataList = $(this).attr('data-lst').split(' ');
            var hide = true;
            for(var d=0;d<dataList.length;d++)
            {
                var index = dataList[d];
                if(enabled[index])
                {
                    hide = false;
                    break;
                }
            }
            if(hide)
            {
                $(this).hide();
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of span elements as below <div> <span class='foo'>foo0</span> <span class='foo'>foo1</span>
I have a set of nested elements like such. <div id=master> <span id=num-1 class=num></span>
I have set the AutoSize property of the form to True and I have
I have block level elements with its height property set in % . Inside
I have a floated span with some text. I have set the overflow to
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have a collection of span elements. In the code I have a global
I have HTML content that generates a dynamic number of span elements with accompanying
I have a problem with overflow. I have a div that set to be
I have the following variables which store the value of a set of cookies:

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.