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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:54:48+00:00 2026-05-22T22:54:48+00:00

I have some JavaScript that toggles the class of the th element clicked to

  • 0

I have some JavaScript that toggles the class of the th element clicked to “ascending” or “descending”.

Q: In the css, how can I display a jQuery-UI icon associated with .ascending or .descending?

<table>
<thead>
<tr>
<th class="ascending">Cust</th>
<th>Name</th>
</tr>
</thead>
...
</table>

Here’s the code, just in case someone spots an inefficiency:

jQuery(function($) {
    $('.thSort th').click(function() {
        var $th = $(this);
        $th.siblings().removeClass('selected ascending descending');
        $th.addClass('selected');
        var column = $th.index();
        var $table = $th.closest('table');
        var rows = $table.find('tbody > tr').get();

        if ($th.hasClass('ascending')) {
            $th.removeClass('ascending');
            $th.addClass('descending');
            rows.sort(function(rowA,rowB) {
                var keyA = $(rowA).children('td').eq(column).text().toUpperCase();
                var keyB = $(rowB).children('td').eq(column).text().toUpperCase();
                if (keyA < keyB) return 1;
                if (keyA > keyB) return -1;
                return 0;
            });
        } else {
            $th.removeClass('descending');
            $th.addClass('ascending');
            rows.sort(function(rowA,rowB) {
                var keyA = $(rowA).children('td').eq(column).text().toUpperCase();
                var keyB = $(rowB).children('td').eq(column).text().toUpperCase();
                if (keyA < keyB) return -1;
                if (keyA > keyB) return 1;
                return 0;
            });
        }
        $.each(rows, function(index,row) {
          $table.children('tbody').append(row);
        });
        return false;
    });
});
  • 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-22T22:54:49+00:00Added an answer on May 22, 2026 at 10:54 pm
    <th scope="col"><div class="floatleft">Topic</div>
    <div class="floatright ui-state-default ui-corner-all">
    <span class="ui-icon ui-icon-circle-triangle-n"></span>
    </div>
    </th>
    

    In JavaScript, toggle between ui-icon-circle-triangle-n and ui-icon-circle-triangle-s.
    If the user clicks on a new th, replace all the html inside the previous th with only the text that is in the first div.

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

Sidebar

Related Questions

I have some javascript that I'm trying to retool using jQuery to learn the
I have some jQuery/JavaScript code that I want to run only when there is
I have a javascript function (function1) that checks some global variables (can the user
I have problem in some JavaScript that I am writing where the Switch statement
I have a view using a master page that contains some javascript that needs
I have some code in a javascript file that needs to send queries back
I need to have some information about the scoping in JavaScript. I know that
Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can
I have some constants in JavaScript that I'd like to reuse in several files
I am have that problem, that I got some javascript that shows a flexibg

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.