+ 1
Jquerry problem
lets say that i have main.js like this main.js $(function(){ function alertHi(){ alert("hi"); } alertHi(); }); everything works fine but let say that i created a second.js file which i wanna call alertHi(); second.js alertHi(); -> gives error because function declaration is in a function so its local i understand that if i put the declaration outside the $(function(){}) it would work but i need it inside
4 Antworten
+ 1
i used window.functionname = function
+ 3
You can solve your problem with a little extra work
sencond.js- $.getScript("main.js",function(True){});
main.js-
$(function(x){
if(x){ alertHi(); }
function alertHi(){
alert("hi");
}
});
+ 1
AshBreez450 look at my last statement i said that i need it inside
- 1
If you do put the function "alertHi()" outside the "$(function(){})", you can call "alertHi" inside and be fine