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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:59:20+00:00 2026-06-10T12:59:20+00:00

Here is my jquery: // Show all instances var link = $(‘<a class=show-instances href=#>Show

  • 0

Here is my jquery:

// Show all instances
    var link = $('<a class="show-instances" href="#">Show all instances</a>');

    $('tr.main').hide().first().find('.product').parent().remove('a').append(link);
    $('tr.main').first().show();

    $(function () {
        $(".show-instances").click(function (e) {
            e.preventDefault();
            $(".show-instances").addClass('selected').not(this).removeClass('selected');
            var selectedClass = $(this).closest('tr.main').attr('class').split(' ');
            $('.' + selectedClass[1]).not(':has("a.show-instances")').toggle();
            return false;
        })
    });

Adding the anchor works and on click adding the class works – I just don’t understand why on click the class added “selected” won’t remove when a user clicks the anchor the 2nd time?

So when a user clicks the anchor “show-instances” class “selected” will add to the anchor – I need the class to be removed when it’s clicked again.

Am I missing another function?

Any suggestions?

/******RESOLVED*******/

Using the Toggle class – here is the jquery:

// Show all instances
    var link = $('<a class="show-instances" href="#">Show all instances</a>');

    $('tr.main').hide().first().find('.product').parent().remove('a').append(link);
    $('tr.main').first().show();

    $(function () {
        $(".show-instances").click(function (e) {
            e.preventDefault();
            $(this).toggleClass("selected");
            var selectedClass = $(this).closest('tr.main').attr('class').split(' ');
            $('.' + selectedClass[1]).not(':has("a.show-instances")').toggle();
            return false;
        })
    });

Also here is a Jsfiddle link to see

  • 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-10T12:59:21+00:00Added an answer on June 10, 2026 at 12:59 pm

    Based on what you’re describing perhaps the toggleClass function would work better for you.

    From the API documentation:

    .toggleClass( function(index, class, switch) [, switch] )
    function(index, class, switch)A function that returns class names to
    be toggled in the class attribute of each element in the matched set.
    Receives the index position of the element in the set, the old class
    value, and the switch as arguments. switchA boolean value to determine
    whether the class should be added or removed.

    Although this one seems pretty straightforward, it can also help if you post these type of questions up on jsfiddle so people can see what you’re trying to achieve.

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

Sidebar

Related Questions

Here's my jQuery: var docname = $('#doc').val(); function parseXml(xml) { $(xml).find(rsp).each(function() { alert(success); });
new to jquery here, right now I have a working hide/show function when one
Need a little help with my jquery here I want all my button with
I would like to have a drop down menu with jQuery show and hide
Can i user jquery to show / hide a specific div on another page?
i'm using jQuery to show/hide different LI-elements based on their classes. Look at this
I've got a good jQuery show/hide function working; the problem is that if the
When the page loads, all the records show. Sorting works great until show-hide is
I am using jQuery to show and hide li elements of a tree(tree is
I'm using .NET 4 and JQuery to show/hide Div's depending on what's selected from

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.