reading online i’ve found that maybe the element ‘image’ isn’t loaded yet when the script is excecuted, but i can’t move that script to the html and place it under the img element as they recommend as the excercise says it must be in separated files
Sorry i´m struggling with my english and js here, both new lang to me with separate files i mean mi scripts are in .js file while the DOM is actually in a .html; and i cannot move the script to the .html to place it before the body; it has to stay in scripts.js
i’ll try the exporting thing later when i’m back on my pc; also i’ll post the whole code here.
Hi Eoja - not sure I agree completely here. There are good reasons for JS to live in both places, hard to say if one is better than the other.
For any JS that needs to run immediately on elements that will live in the body, you’re right, the JS should render later. This could be from being placed just before closing body, or from placing the JS inside of a load event on the body.
If using a load event, placing in <head> works fine. There are also good reasons for getting JS started (especially asynchronous JS) in the head, if it doesn’t necessarily rely on elements in the body (analytics, api calls, etc).