Can you do this?
var myFunction = function(){
$(function(){
// jQuery code here
$("#myField").hide();
})
}();
I had some code like this which worked fine almost everywhere but then I discovered it only worked about 80% of the time in FF 9.0.1. The fix was to do this:
var myFunction = function(){
$(function(){
// jQuery code here
$("#myField").hide();
})
};
myFunction();
Now I’m a bit puzzled why this was necessary
EDIT:
I can see this is a bit confusing. Maybe what I should have done would have been this instead:
var myFunction = function(){
// jQuery code here
$("#myField").hide();
};
$(function(){
myFunction();
});
The problem is that you are not correctly defining the function and then putting jQuery code, when the
JavaScriptparser reads you code it will ignore the var definition and execute thejQuerythat you defined on document ready. In case you don’t know:The best option for you would be to create a function like: