Closed mblitstein closed 6 years ago
Hi there,
I've tried out the GitHub version of the example (https://mdn.github.io/beginner-html-site-scripted/), and it seems to work fine for me. No errors or anything.
What browser are you trying to run the example in?
I tried it in Firefox, Chrome, and Edge.
I started in Codepen. I'm beginning to think the problem may be in the pathnames.
Thanks
Ah yes - it uses relative paths, which would break if you put it in codepen. If you tried absolute paths, it would probably work.
I'm trying to learn JS basics, however also got stuck with this error
TypeError: myImage is null
in line:
myImage.onclick = function() {
At the same time, if I put the script just in js console in browser, it works. Maybe it's connected with Visual Studio Code, I'm writing in.
@ovirchenko this sounds like the value of myImage
is being incorrectly set, i.e. probably not selected like you are intending. Can I have a look at your full source code?
@chrisdavidmills Thank you for the answer! I've understood what I did wrong by mistake. Put
<script src="scripts/main.js"></script>
before </head>
. Now it's in the end before </body>
and it works.
@ovirchenko Excellent; glad you got it worked out.
I got error messages indicating that myImage wasn't being set to the name of the image.
This was confirmed by an error trap (if(myImage === null ) {alert(myImage is null) .
I finally copied the GitHub version which replicate the previous bad behavior. The errant code appears to be: var myImage = document.querySelector('img');
Has anyone else had this experience, or more importantly a fix?
Thanks