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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:10:06+00:00 2026-05-29T08:10:06+00:00

I have a list that when a link is selected, the div’s associated will

  • 0

I have a list that when a link is selected, the div’s associated will hide.

First of all, is there an easier way to write the code to make the selector find the data associated to the button pressed?

Secondly, when multiple links are selected and one is clicked again, the list goes back to default. Is there a fix for this?

    $(document).ready(function() {

        $('#show-free').click(function() {

            if ($('#show-free').hasClass('active')) {
                $('.book[data-price!="0"]').trigger('show')
                $(this).removeClass('active');

            } else {
                $('.book[data-price!="0"]').trigger('hide');
                $(this).addClass('active');
            }
        });

        $('#show-paid').click(function() {

            if ($('#show-paid').hasClass('active')) {
                $('.book[data-price="0"]').trigger('show')
                $(this).removeClass('active');
            } else {
                $('.book[data-price="0"]').trigger('hide');
                $(this).addClass('active');
            }
        });

        $('#show-new').click(function() {

            if ($('#show-new').hasClass('active')) {
                $('.book[data-weeks-on-list="0"]').trigger('show')
                $(this).removeClass('active');
            } else {
                $('.book[data-weeks-on-list="0"]').trigger('hide')
                $(this).addClass('active');
            }
        });


        $('#show-old').click(function() {

            if ($('#show-old').hasClass('active')) {
                $('.book[data-weeks-on-list!="0"]').trigger('show')
                $(this).removeClass('active');
            } else {
                $('.book[data-weeks-on-list!="0"]').trigger('hide')
                $(this).addClass('active');
            }
        });


        $('.book').on('show', function() {
            $(this).show('slow');
        }).on('hide', function() {
            $(this).hide('slow');
        })


    });
  • 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-29T08:10:07+00:00Added an answer on May 29, 2026 at 8:10 am

    To ease finding the data associated with a link use the data() JQuery method maybe

    $('.book').filter(function(obj){
       return obj.data('price') != '0';
    }
    

    instead of

    $('.book[data-price!="0"]')
    

    Actually is that any better – i suspect not. It’s just an alternative.

    With the click functions – because you are not returning false in the method then the default behaviour of the link will be fired which i would imagine would cause the links to reset. I would try returning false within the clicks just to supress this behaviour.

    Does this help at all?

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

Sidebar

Related Questions

I have a dropdown list that reloads the page when its selected value is
I have a DIV with a list of radio buttons and a 'selected search'
I have Javascript function that is adding css class current to selected link <a>
I have a list that looks like (A (B (C D)) (E (F))) which
I have a List that contains items, for example: 1) https:\\10.12.23\\ 2) https:\\12.23.12.25\\ 3)
I have one list that I want to take a slice of, reverse that
I have a list that I need to send through a URL to a
I have a list that has some chapter numbers in string. When I sort
Hello I have this list that i am working on. When i move the
Suppose I have a list that I wish not to return but to yield

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.