Copy link to clipboard
Copied
This is a follow up on a problem that was encountered yesterday. The original post can be found here:
https://community.adobe.com/t5/Dreamweaver/Javascript-onmouseover-does-not-work/td-p/10681988
In a few words the problem was that a code I had written in Javascript for my website did not work in Dreamweaver HTML code, whereas it worked in jsfiddle and in theory also in W3schools site.
The problem was solved when I moved the Javascript code to the bottom of the HTML code, right before the </body> tag. Previously I had linked it through <script src"..."></script> at the head and it didn't work. As soon as I moved it as the last line inside the <body> it functioned as it should.
I am new in coding and I haven't quite worked with scripts at both the <head> and at the <body> as it is mentioned here https://www.w3schools.com/js/js_whereto.asp , and why one works and the other doesn't, but general consensus as far as I a have read is for the script to be put at the bottom of the page.
If anyone has any insight on the matter, please share it so that people like me with zero experience in coding can benefit.
Cheers,
Daniel
If you insert the javascript at the top of the page it runs before the whole page has finished loading therefore it has no effect on the elements you wish to add events to. If you insert it at the bottom it runs after the page had loaded and therefore it has an effect on the elements you wish to add events to.
Copy link to clipboard
Copied
If you insert the javascript at the top of the page it runs before the whole page has finished loading therefore it has no effect on the elements you wish to add events to. If you insert it at the bottom it runs after the page had loaded and therefore it has an effect on the elements you wish to add events to.
<script src="blah.js" defer></script>
Copy link to clipboard
Copied
Tried it and works like a charm! Thanks!