Highlighted

SOLVED: Javascript "onmouseover" does not work

Community Beginner ,
Oct 21, 2019

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.

 

  1. You can add the defer attribute to the script tag if you wish to keep the javascript at the top of the page.  This will have the effect of only evoking the javascript after the rest of the page has loaded.

 

<script src="blah.js" defer></script>

Views

48

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

SOLVED: Javascript "onmouseover" does not work

Community Beginner ,
Oct 21, 2019

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.

 

  1. You can add the defer attribute to the script tag if you wish to keep the javascript at the top of the page.  This will have the effect of only evoking the javascript after the rest of the page has loaded.

 

<script src="blah.js" defer></script>

Views

49

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 21, 2019 0
LEGEND ,
Oct 21, 2019

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.

 

  1. You can add the defer attribute to the script tag if you wish to keep the javascript at the top of the page.  This will have the effect of only evoking the javascript after the rest of the page has loaded.

 

<script src="blah.js" defer></script>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 21, 2019 1
Community Beginner ,
Oct 21, 2019

Copy link to clipboard

Copied

Tried it and works like a charm! Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 21, 2019 0