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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:42:18+00:00 2026-06-04T04:42:18+00:00

Perhaps I am doing this incorrectly/inefficiently but this isn’t working for me: $(document).ready(function(){ $(‘li.taglink’).click(function(){

  • 0

Perhaps I am doing this incorrectly/inefficiently but this isn’t working for me:

$(document).ready(function(){

    $('li.taglink').click(function(){
        alert('clicked tag');
        $userClicked = $(this).html();
        $('#holder').children('div').each(function () { 
            $('li.taglinkcurrent').removeClass('taglinkcurrent').addClass('taglink');                                       
            $x = $(this).attr("tags");
            ele = $x.split(',');
            for (var i = 0; i < ele.length; i++) 
            {
            if ($userClicked == ele[i]) {$(this).show(495); break;} 
                                    else {$(this).hide(495);}   
            }
        });
        $(this).removeClass('taglink').addClass('taglinkcurrent');
    });

    $('li.taglinkcurrent').click(function(){
        alert('clicked current');
        $('li.taglinkcurrent').removeClass('taglinkcurrent').addClass('taglink');                               
        $('li.taglink').show(495);
    });

});

The page contains divs with “tags” attributes that contains several tags. I also have an unordered list, with each li element containing the individual tags. When a user clicks one of the li elements, it shows all the divs that have that tag, and hides everything else. If a user clicks that same li element, it then shows everything once again. I added in the alerts to test what was going on, and every time I click a link it pops up “clicked link” even when the li had its class switched to .taglinkcurrent. Any ideas of what I’ve done wrong?

  • 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-04T04:42:19+00:00Added an answer on June 4, 2026 at 4:42 am

    I suppose the event is attributed to each li on load, and the subsequent class changes doesn’t unbind the event.
    But you can easily fix this this way, I think :

    $('li').click(function() {
        if ( $(this).hasClass("taglink") ) {
            alert("clicked tag");
            ...
        } else if ( $(this).hasClass("taglinkcurrent") ) {
            alert('clicked current');
            ...
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps this is my lack of understanding, but I would have assumed that doing
Perhaps this question has been asked elsewhere, but I'm unable to find it. With
Perhaps this has something to do with it being the mainForm, but I'll ask
Perhaps I am doing this wrong and suggestions on how to improve my code
Is there an elegant way of doing this? Perhaps with Linq? For something like
[I am doing this work in Java, but I think the question is language-agnostic.]
I'm actually trying doing this in Java, but I'm in the process of teaching
Perhaps I am not getting SQL Parameters correctly, but this doesn't work for me.
Perhaps I'm doing this wrong. I want to set up a base class and
Perhaps I am going about this wrong, but I am following git tutorials as

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.