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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:51:27+00:00 2026-05-23T23:51:27+00:00

I have created a search page using parametric filtering conducted on change of checkbox

  • 0

I have created a search page using parametric filtering conducted on change of checkbox values.

http://jsfiddle.net/s9FjY/4/

    $('#parameters input[type="checkbox"]:enabled').bind('change', function(e) {
      var $this = $(this),
        $checkedBoxes = $('#parameters').find('input:checkbox').filter(':checked').length,
        index = $('#parameters input:checkbox').index($this),
        txt = jQuery.trim($this.parent().text());
      if ($checkedBoxes === 0) {
        //remove all filters
        $('#filters > ul > li').remove();
      } else {
        if ($this.is(':checked')) {
          // add filter text
          var filterLink = $('<li>' + txt + '<span>Remove filter</span></li>');
          $.data(filterLink, 'myIndex', index);
          alert($.data(filterLink, 'myIndex'));
          $('#filters > ul').append(filterLink);
        } else {
          // remove filter text
          $('#filters > ul').find('li[class=' + index + ']').remove();
        }
      }
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<ul id="parameters">
  <li>
    <label for="premium">
      <input type="checkbox" id="premium" name="filters" value="true" />Premium
    </label>
  </li>
  <li>
    <label for="articles">
      <input type="checkbox" id="articles" name="articles" value="true" />Articles
    </label>
  </li>
  <li>
    <label for="news">
      <input type="checkbox" id="news" name="news" value="true" />News
    </label>
  </li>
  <li>
    <label for="other">
      <input type="checkbox" id="other" name="other" value="true" />Other
    </label>
  </li>
</ul>

<div id="filters">
  <p>Filters applied:</p>
  <ul>
    <!-- Filters applied insert here -->
  </ul>
</div>

I am displaying which filter was applied in a dynamic list and storing the association on the list filter element with jQuery’s .data() method.

Now, when I un-check the appropriate checkbox I want to remove the filter li element based on the data that is stored on the said element. I was previously doing this on the class attribute but thought using .data() was a neater solution.

Can’t quite figure out how to remove the appropriate list element?

  • 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-23T23:51:28+00:00Added an answer on May 23, 2026 at 11:51 pm
    1. Why are you using class? You never defined class names.

    2. There is $(this).data which works seamlessly: http://jsfiddle.net/s9FjY/7/.

    3. You do not need separate code for 0 checked checkboxes.

    The code:

    $('#parameters input[type="checkbox"]:enabled').bind('change', function(e){
        var $this = $(this),
            $checkedBoxes = $('#parameters').find('input:checkbox').filter(':checked').length,
            index = $('#parameters input:checkbox').index($this),
            txt = jQuery.trim($this.parent().text());
        if ($this.is(':checked')) {
            // add filter text
            var filterLink = $('<li>' + txt + '<span>Remove filter</span></li>');
            $(filterLink).data('myIndex', index);
            alert($(filterLink).data('myIndex'));                
            $('#filters > ul').append(filterLink);
        } else {
            // remove filter text
            $('#filters > ul').find('li').filter(function() {
                return $.data(this, 'myIndex') === index;
            }).remove();
        }  
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning, I have created an ASP.NET 3.5 webform that allows users to search
I have created a search page uising exposed filters and views module. The user
I've created a blog main page using PHP and have included a sidebar and
I'm using ASP.NET with C# 2.0. I have created some objects for a database
I have created a search page in a Windows 8 Style App. I have
I have created a search engine for my website using Google Webmaster Tools. Now
We are using Yii Framework and have created a search form to include the
I have created a page where I perform a search and the number of
I have created an index.jsp as the start page in an Eclipse project using
I have created a search bar for my website, the user may search a

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.