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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:53:53+00:00 2026-05-22T18:53:53+00:00

I am having some trouble getting a toggle function to work and need someone

  • 0

I am having some trouble getting a toggle function to work and need someone to help explain it to me.

My HTML (simplified):

<div id="filter_names"></div>

<div class="item">Option 1</div>
<div class="item">Option 2</div>
<div class="item">Option 3</div>
<div class="item">Option 4</div>

My jQuery (simplified)

$(".item").click(function(){

  var tagname = $(this).html();
  $('#filter_names').append(' > '+tagname);

  $(".loading").show();

});

As you can see I am appending clicked items’ value to the div at the top. This works fine, but i need it to be removed when i click it again.

I am pretty sure it needs a toggle() function but so far my attempts have been pretty fruitless.

Some guidance would be greatly appreciated.

EDIT: You can see what i want to achieve in this JSfiddle. It’s working exactly how i want it to by appending a value to the end (like a breadcrumb link), but is not being removed when i click it again.

  • 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-22T18:53:54+00:00Added an answer on May 22, 2026 at 6:53 pm

    You need to look at the #filter_names contents and check if the clicked tag’s value is already included, then remove it if it is, or add it otherwise:

      if (filternames.indexOf(tagname) === -1) {
        $('#filter_names').append(' > '+tagname);
      } else {
        $('#filter_names').text(filternames.replace(' > '+tagname, ''));
      }
    

    Working fiddle: http://jsfiddle.net/passcod/Kz3vx/

    Note that you might get weird results if one tag’s value is contained in another’s.

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

Sidebar

Related Questions

I am having some trouble getting a function to work in internet explorer (7-8).
I am having some trouble getting this working: $(#cloud1).live(mouseenter, function() { $(this).append('<div class=cloud1><img src=http://mercury-consulting.theportlandco.com/wp-content/uploads/2010/10/1.png
I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the
I am having some trouble getting Elmah to work with url routing in an
I'm having some trouble getting my Table and Colspans to work. I'm trying to
I am having some trouble getting this simple code to work: #pragma once #include
I'm having some trouble getting the code statement beneath to work as intended. The
I'm having some trouble getting a jQuery plugin to work correctly in my MVC
I'm having some trouble getting my cache to work the way I want. The
Having some trouble getting this query to work correctly. mysql_query(DELETE FROM `table` WHERE `id`

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.