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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:05:06+00:00 2026-05-11T17:05:06+00:00

I’m using this in conjunction with the tablesorter plug-in, my goal is to have

  • 0

I’m using this in conjunction with the tablesorter plug-in, my goal is to have a blank class attribute in any column that is not being sorted, i.e. when I click one column the class attributes in the others are removed.

I have a table with a whole bunch of headers, basically what I want to be able to do is when I click on a table header, I wanna all other tables to have their css class removed, but the one I’m clicking on should be toggling between two css classes. I’m using a rel tag within an anchor tag in the content of the header, I do this because we’re using XHTML Strict and rel can’t be defined in the table header tag itself. My code is as follows:

$(function() {
     $("a[rel='Header']").click(function () {

         $("a[rel='Header']").each(function() {
            if($(this).attr("class")=="sort-up"){$(this).removeClass("sort-up");}
            if($(this).attr("class")=="sort-down"){$(this).removeClass("sort-down");}
        })

         if($(this).attr("class")==""){$(this).addClass("sort-up");}
            $(this).toggleClass("sort-down")
            });      
});

What I’m assuming it should be doing is as soon as a header is clicked, cycle through each header, if it contains the class attribute “sort-up”, remove it; if it contains the class attribute “sort-down”, remove it. Then, for the currently clicked header, add the class attribute “sort-up” and toggle between the “sort-down” attribute. My problem is that when I click on one header, if it’s using the “sort-down” class, represented in the header by a down arrow(/), then I go and click on another header in a different column, the attribute doesn’t get removed. It will, however, remove the “sort-up” class (^).
Here is a list of my header in XHTML:

<thead>
            <tr>
                <th><a rel = "Header" href="#" class="">Title</a></th>
                <th><a rel = "Header" href="#" class="">Instructor</a></th>
                <th class="{sorter: 'usLongDate'}"><a rel = "Header" href="#" class="">Date</a></th>
                <th class="{sorter: false}">Start/End</th>
                <th><a rel = "Header" href="#" class="">Seats Available</a></th>
                <th><a rel = "Header" href="#" class="">Enrolled</a></th>
                <th><a rel = "Header" href="#" class="">Pre-Requisites</a></th>
                <th class="{sorter: false}">Workshop Actions</th>
            </tr>
        </thead>

UPDATED with changes recommended by waxwing, stupid mistake, it works, I wasn’t paying attention to the syntax of the hasClass. Thanks.

$(function() {
     $("a[rel='Header']").click(function () {

         $("a[rel='Header']").each(function() {
            if($(this).hasClass("sort-up")){$(this).removeClass("sort-up");}
            if($(this).hasClass("sort-down")){$(this).removeClass("sort-down");}
        })

         if($(this).hasClass("")){$(this).addClass("sort-up");}
             if ($(this).hasClass("sort-up")) { 
                    $(this).removeClass("sort-up").addClass("sort-down"); 
                } else {
                    $(this).removeClass("sort-down").addClass("sort-up");
                }
            if($(this).attr("title") == "Sort column in ascending order"){
                $(this).attr({title : "Sort column in descending order"});}
            else {$(this).attr({title : "Sort column in ascending order"});} 
            });      
});
  • 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-11T17:05:06+00:00Added an answer on May 11, 2026 at 5:05 pm

    Try:

    $(function() {
      $("a[rel='Header']").click(function () {
        // store the header and this for later use
        var $thead = $(this).parents().filter("thead").slice(0,1);
        var $this = $(this);
    
        // if we were sort-up - we become sort-down - otherwise we become sort-up
        if ($this.hasClass('sort-up')) { 
          $this.removeClass('sort-up').addClass('sort-down');
        } else {
          $this.removeClass('sort-down').addClass('sort-up');
        }
    
        // all headers except the one we clicked on - remove sort classes
        $("a[rel='Header']",$thead).not($this[0]).each(function() {
          $(this).removeClass('sort-up').removeClass('sort-down');
        });
    
        // set link titles based on current class
        $("a[rel='Header']", $thead).each(function() {
          if ($(this).hasClass('sort-up'))
          {
            $(this).attr('title', 'Sort column in descending order');
          } else {
            $(this).attr('title', 'Sort column in ascending order');
          }
        });
        // end click function
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.