How can I solve this scope issue:
I am trying to update an old project.
HTML file includes JS file.
after some code from the JS is running, it calls back a function myFunc()
from the HTML.
In the new code, I need to add jQuery ready function
to the HTML file.
so I get error
jQuery.Deferred exception: myFunc is not defined
what is the minimum change I can make in the JS code (or in the HTML code?) to solve this scope issue?
my HTML file:
<html>
<head>
... html code ...
<script src="/my.js"></script>
</head>
<body>
... html code ...
<script>
$( document ).ready(function() { // <- this line was added to the new HTML file
...
function myFunc() { // was called from JS file. but now is considered undefined :(
...
}
}); // <- this line was added to the new HTML file
</script>
</body>
</html>
my JS file:
(function($){
$(document).ready(function(){
...
myFunc();
...
});
})(this.jQuery);