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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:54:19+00:00 2026-05-28T05:54:19+00:00

Ok, so I have this jquery function to that grabs the checkbox’s value and

  • 0

Ok, so I have this jquery function to that grabs the checkbox’s value and uses as identifier to show or hide an ul

The problem is that I couldn’t manage to add an if only 1 choice in checkbox add X.

Here is the code and what I have tried

$('#filter li input:checkbox').change(
    function(){
        var show = $('input:checkbox:checked').map(function(){
           return $(this).val();
        });
        if (show.length > 0)
        {
                $('#list li').each(
                function(){
                    /*if ($.inArray($(this).attr('class'),show) <= 1)
                    {
                        console.log($(this));
                    }
                    else */if ($.inArray($(this).attr('class'),show) > -1)
                    {                        
                        $(this).show();
                    }
                    else
                    {
                        $(this).hide();
                    }
                });
        }
        else {
            $('#list li').show();
        }
    });

I don’t really understand how this works: if ($.inArray($(this).attr('class'),show) > -1) because I have tried if ($.inArray($(this).attr('class'),show) = 1) and nothing

  • 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-28T05:54:20+00:00Added an answer on May 28, 2026 at 5:54 am

    You’re assigning a value in the if clause:

    if ($.inArray($(this).attr('class'),show) = 1)
    

    To break it down, what this is actually saying is equivalent to

    $.inArray($(this).attr('class'),show) = 1;
    if ($.inArray($(this).attr('class'),show))
    {
        ...
    

    You should use the == comparison operator

    if ($.inArray($(this).attr('class'),show) == 1)
    

    Or, more correctly avoiding type coersion, use ===

    if ($.inArray($(this).attr('class'),show) === 1)
    

    This will avoid comparison between 1 and "1" returning true

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

Sidebar

Related Questions

Here's the story... I have a jQuery function that does something, this function is
I have this jQuery: $(document).ready(function() { $(#panel).hide(); $('.login').toggle( function() { $('#panel').animate({ height: 150, padding:20px
I have this piece of Jquery code that grabs a heading in a table
peace folks, I have this small piece of jquery based code, that grabs all
I have created a jQuery plugin that grabs a JSON feed (in this case
I have this jQuery which works fine $(li[id^='shop_id']).click( function () { alert(I clicked on
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have this code in jquery : $(#order_btn).click(function(){ var totalprice = $(.price_amount).text(); $(#totalprice).val(totalprice); });
I have this code in jQuery.. $(document).ready(function(){ var fieldCounter = 0; ... I have

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.