[jQuery] How can I improve the performance of this code?
the code:
var choiceShownArray = new Array();
var cache1 = $("span[class^='matrix_choice_']");
var cache2 = $("input[id^='showChoice']");
var cache3 = $(".has_outcome");
var cache4 = cache3.find("span[class^='matrix_choice_']
[cchar='']").next().andSelf();
function changeShowChoice() {
cache1.show();
var showingAll = true;
useNum = document.getElementById
("option_matrix_outcome_use_number").checked;
cchar = useNum ? (document.getElementById
("option_matrix_total_use_fraction").checked ? "cfrac" : "cint") :
"cchar";
for (var i = 1; i <= <?= count($mapping_choices) ?>; i++)
{
$(".matrix_choice_"+i).each( function () {
$(this).html( $(this).attr(cchar) );
});
}
choiceShownArray = choiceShownArray || [];
cache2.each( function(i) { choiceShownArray[i] = useNum ? true : $
(this).attr("checked"); $(this).attr("disabled", useNum); });
if( !useNum )
{
for(i = 0; i < choiceShownArray.length; ++i)
{
if( !choiceShownArray[i] )
{
$("span[class='matrix_choice_"+(i+1)+"']").next().andSelf().hide
();
showingAll = false;
}
}
cache4.hide();
cache3.find("span[class^='matrix_choice_']:visible:last").each
( function() {
if( $(this).hasClass("matrix_choice_seperator") )
$(this).hide();
});
}
--- end code ---
--- html ---
<td valign="middle" align="center" class="has_outcome"
width="125px"><span class="matrix_choice_1" cchar="Ta" cint="1"
cfrac="1.0">Ta</span><span class="matrix_choice_seperator"
style="display:none;">, </span><span class="matrix_choice_2" cchar=""
cint="0" cfrac="0.0"></span><span class="matrix_choice_seperator"
style="display:none;">, </span><span class="matrix_choice_3"
cchar="Ka" cint="1" cfrac="1.0">Ka</span><span
class="matrix_choice_seperator" style="display:none;">, </span><span
class="matrix_choice_4" cchar="61" cint="1" cfrac="1.0">61</span><span
class="matrix_choice_seperator" style="display:none;">, </span><span
class="matrix_choice_6" cchar="" cint="0" cfrac="0.0"></span><span
class="matrix_choice_seperator" style="display:none;">, </span><span
class="matrix_choice_7" cchar="" cint="0" cfrac="0.0"></span></td>
--- end html ---
Is there any changes could be made to the above code to improve the
performance?
There are around 800 of this type of <td> in the table and about 70%
are of class "has_outcome" while the other is of class "no_outcome".
Thanks a lot.