I'm trying to call a function within the html page from an external loaded index.js file, but I always get
Uncaught ReferenceError: displayy is not defined
Inside my html page:
<script type="text/javascript" src="index.js"></script>
<script>
$( document ).ready(function() {
displayy();
});
</script>
The index.js file:
$( document ).ready(function() {
alert('loaded');
function displayy() {
alert('executed');
}
});
I've also tried:
<script>
window.onload = function() {
displayy();
};
</script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
displayy();
});
</script>
displayyis not defined in the environment where you want to call it.displayyfunction inside the html script tag and run it from there. That way it's working.displayyfunction inside the html script tag and run it from there." Yes, then it's defined in global scope. There is no reason to put the declaration inside the thedocument.readycallback. Have a look at learn.jquery.com/using-jquery-core/document-ready to get a better understand of when document.ready is necessary.