Thank you for your answer.

With your code, the script is much faster, but it however remains much much
slower than writing "normal" javascript
You can compare the performances, I update the script with your line of
code.



Renato Formato wrote:
> 
> 
> mathmax ha scritto:
>> 
>> When I discovered jquery, I wanted immediately to remake this script to
>> see
>> how shorter the script could be. I was however quickly stopped by the
>> performances... Here, you can see the 
>> http://fra.orkos.com/tests/pricelist/
>> same page  but the research script has been replaced by two jquery lines
>> of
>> code. (the script is slow and may blocks the browser during a few
>> seconds.
>> Do not stop script, it will not block you a long time)
>> 
>> $(".Name").parents("tr").hide(); //hide all the lines
>> $(".Name:contains('"+tbxValue+"')").parents("tr").show(); //then display
>> the
>> lines in which the column "Name" contains the text researched
>> 
>> You can see how this second script is slow. Moreover, I didn't mask the
>> empty categories or filter the hierarchy at left hand side as in the
>> first
>> script...
>> 
>> Maybe I could increase a little the performance by writting these two
>> lines
>> of code differently, but the gap of performance between those two scripts
>> is
>> so huge, that I wonder if using jquery with such page is a good choice.
>> Could you give me your advice ?
> 
> 
> This is a one line version that should be much faster.
> $('td.Name').parent().hide().end().contains(tbxValue).parent().show();
> 
> The important points are:
> 1) not to select elements by class only if you know all the elements 
> having that class have the same tagName.
> (td.Name and not .Name)
> 
> 2)don't use parents('tr') if you just nedd the parent element (the tr)
> (parent() and not parents('tr'))
> 
> 3)don't select the same elements multiple times, use the chain.
> $('td.Name').parent().hide().end().contains(tbxValue);
> 
> and not
> 
> $('td.Name').parent().hide();
> $('td.Name').contains(tbxValue);
> 
> 
> 
> 
> However, as all the td and tr elements are always the same, you could 
> store them, instead of selecting all again on each keypress.
> 
> 
> You could store in two global vars the elements:
> $td = $('td.Name');
> $tr = $td.parent();
> 
> and write this inside your function:
> $tr.hide()
> $td.contains('a').parent().show();
> 
> 
> Let me know if you have any speed gain.
> 
> Ciao
> Renato
> 
> 

-- 
View this message in context: 
http://www.nabble.com/jquery-is-slow-at-execution-tf3898682s15494.html#a11053627
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to