I am building a sortable table and need the update the 'sort order' icons on the table header.
Here is a little information so you can better understand what my code is doing.
The code is being executed from within a click event, and $(this)
references the table header cell being clicked.
The table header cell has three spans in it; a wrapper, a text span, and a icon span. Here is how it looks
<span class='ui-button ui-widget ui-state-default ui-button-text-icon-secondary'>
<span class='ui-button-text'>text</span>
<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-2-n-s'></span>
</span>
collection
is a return from $("thead:first th")
and here is my code that does the switch on the icons.
var new_class = sort_info.order == "asc" ? "ui-icon-triangle-1-n" : "ui-icon-triangle-1-s";
collection.find(".ui-icon").removeClass("ui-icon-triangle-1-n ui-icon-triangle-1-s ui-icon-triangle-2-n-s").addClass("ui-icon-triangle-2-n-s");
$(this).find(".ui-icon").removeClass("ui-icon-triangle-1-n ui-icon-triangle-1-s ui-icon-triangle-2-n-s").addClass(new_class);
as you can see it selects all header icon cells, removes any icon classes that may exist, then re-adds the applicable class. THEN i grab the clicked cells' icon, remove any icon classes, and apply the appropriate class.
Is this the best way to do this? It works.. and it executes in roughly 7 ms (Windows 7, FF6.0) which is ok by me.. just looks like it's a lot of work being done.
any thoughts?