JS load order with jQuery on load inside a function that executes immediately -


can this?

var myfunction = function(){     $(function(){         // jquery code here         $("#myfield").hide();     })     }(); 

i had code worked fine everywhere discovered worked 80% of time in ff 9.0.1. fix this:

var myfunction = function(){     $(function(){         // jquery code here         $("#myfield").hide();     })     }; myfunction(); 

now i'm bit puzzled why necessary

edit: can see bit confusing. maybe should have done have been instead:

var myfunction = function(){      // jquery code here     $("#myfield").hide();        };  $(function(){     myfunction(); }); 

the problem not correctly defining function , putting jquery code, when javascript parser reads code ignore var definition , execute jquery defined on document ready. in case don't know:

 $(function(){})  // equivalent   $(document).ready(function(){}).  

the best option create function like:

 function myfunction(){        $("#myfield").hide();   }   $(function(){      //after whenever want      myfunction();   })     

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -