Christof Donat schrieb:
Hi,

How can I change this to my code runs faster?

I don't think, that you should change jQuery here. As much as I understand it, that function is called whenever you use a more complex expression than just an ID, a tag name or a classname.

1. Try to give your input-Elements IDs and use $("#myid").filter("[EMAIL 
PROTECTED]")
instead of "[EMAIL PROTECTED]'patrimoniais__pat_co_veiculos'[EMAIL PROTECTED]". Then jQuery can use document.getElementByID() to get the Element and checks for the condition in the filter. I am not shure if jQuery will do the same for $("[EMAIL PROTECTED]"). You could profile to see if there is a difference.

2. Use chaining and try to cache jQuery results:

----
$('#dadosAuxiliares').tabs( {fxShow: {height: 'show', opacity: 'show'}, 
tabStruct:'.fragment'});
$('#dadosAuxiliares').triggerTab(0);
----

can be
----
$('#dadosAuxiliares').tabs( {
fxShow: {height: 'show', opacity: 'show'}, tabStruct:'.fragment'} ).triggerTab(0);
----

Then the query for '#dadosAuxiliares' onlyneeds to be executed once.

----
$("[EMAIL PROTECTED]'familiares__pes_ds_dependente_possui']").click(function(){
        // apresenta um highlight na linha clicada
        
$('.show_familiares__pes_ds_dependente_possui').highlightFade({color:'yellow',speed:1500,iterator:'sinusoidal'});
        if ($("[EMAIL PROTECTED]'familiares__pes_ds_dependente_possui'[EMAIL 
PROTECTED]").val() == "1"){
                $(".show_familiares__pes_ds_dependente_possui").show();
        }
        else{
                $(".show_familiares__pes_ds_dependente_possui").hide();
        }
});
----

can be
----
var p = $("[EMAIL PROTECTED]'familiares__pes_ds_dependente_possui']");
var shp = $('.show_familiares__pes_ds_dependente_possui');
p.click(function{
        shp.highlightFade({color:'yellow',speed:1500,iterator:'sinusoidal'});
        if( p.filter('[EMAIL PROTECTED]').val == 1 ) shp.show();
        else shp.hide();
        p.end(); // remove the filter result
});
----

Then p and shp are only queried once during the whole life of the script.

Christof


I saw another thing, if you know the type in the shp query, that will make it faster as well:

shp = $('tr.show_familiares__pes_ds_dependente_possui');

Another idea I had is to use context for your queries. Currently you searching through the complete DOM and not the relevant parts only.

If for example you know that relevant elements are all contained by the element inside the div with the id "familiares", the following could improve speed:

var context = $('#familiares');
$('tr.show_familiares__pes_ds_dependente_possui', context);

Last not least, and that may be hard to hear: using a modern CSS based layout instead of a bloated table based layout could improve speed of your queries, simply because there's less elements to search through. But that will also depend on the selectors you use. If you don't use type selectors than it will matter, if you do it becomes less relevant.



-- Klaus








Reply via email to