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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:16+00:00 2026-06-13T02:26:16+00:00

I am working on a simple method for filtering elements depending on their class.

  • 0

I am working on a simple method for filtering elements depending on their class. The user checks a checkbox and the jQuery does it’s thing fine and turns off any element depending on the class. The line that turns off the element, and how the elements look is:

$('#ItemList div:not(.' + Filter + ')').hide();
<div class="1 2 3">asdf</div>

However I want to be able to use the data-xxxx attribute to do this instead of the class attribute, but I am having problems actually selecting the elements this way. What I have is below:

$("#ItemList div:not([data-filter'" + Filter + "'])").hide();
<div data-filter="1 2 3">asdf</div>

So, how do I go about selecting the element using the data-filter attribute instead of the class? The methods I have found on here are not working for me!
Many thanks.

UPDATE

Okay, so James Allardice’s reply did the trick. But has caused another issue that I probably should I said in the original post.

Each data-xxxx attribute can have a number of values, I need this filter to work so that if any one of the value shows up it will not hide the element.

$('#Filters input').change(function()
{
    $('#ItemList div').show();
    $('input').each(function()
    {
        var Checked;
        if(Checked = $(this).attr('checked'))
        {
            var Filter = $(this).attr('data-filter');
            $("#ItemList div:not([data-filter='" + Filter + "'])").hide();
        };
});

<div data-filter="1">1</div>
<div data-filter="1 3">1 3</div>

So for example if a checkbox with the following attribute is checked it will show both divs:

data-filter="1"

But if the attribute is like this it will only show the second:

data-filter="3"
  • 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-13T02:26:17+00:00Added an answer on June 13, 2026 at 2:26 am

    You can use the jQuery filter function like this:

    $("#ItemList div").filter(function()
        {
            var attr = $(this).attr('data-filter');
            var filterArr = attr.split(" ");
            return $.inArray(Filter, valArr) == -1;
        }
    ).hide();
    

    I haven’t tested this but it should work.
    You can find the inArray documentation from the this link and the documentation for the filter function from this link

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

Sidebar

Related Questions

I have this very simple method called to check if a user has a
I am Working on simple login application in which user is first shown login
I am working on this very simple method I know I am very close
With jquery.mobile-1.0rc1 ; getting error while working in simple dialog- error-message in Chrome- Uncaught
I have this simple method: def my_method ...here I am working with params MyMailer.send_email_to_user(params).deliver
The simple working query, list the number of licenses for each license type: Query:
I'm trying to make a simple text editor with winapi, its working for simple
Good Day, I have a simple working routine in Perl that swaps two words:
Working on a simple C program I'm stuck with an if test: int line_number
Working on a simple TimeTracker App. You start a timer, wait a certain time,

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.