javascript not in < head > </ head> ?

merlin's picture

They have: 410 posts

Joined: Oct 1999

i need to place some javascript (simple img-mouseover) into the body of a page.
i thought, it would be possible to just use <script></script> in the body part and place the code between. since i'm not good in javascript, i didn't get it to work.
could someone post some code-samples? i took mine out of hotscripts.com but everywhere <script> is placed in the head... Sad

tia! Smiling

taff's picture

They have: 956 posts

Joined: Jun 2001

The script itself should be in the header and called from the body. The reasoning here, in simplistic terms, is to ensure that the script is loaded before it is called.

There ARE cases where a script can reside in the body but mouseovers aren't one of them.

I do recall seeing the following structure depicted somewhere:

*
*

<script>
*
*
</script>

*
*

I have no idea if this works.

For samples try javascripts.com
For a tutorial try http://webteacher.com/javascript/

.....

merlin's picture

They have: 410 posts

Joined: Oct 1999

thank you taff.

Quote: The reasoning here, in simplistic terms, is to ensure that the script is loaded before it is called.

convinces me.

well, since this mouseover is not THAT important, i just start the animation after n seconds and don't make the mouseover.

except anyone else knows a way?

thanks anyway! Smiling

They have: 488 posts

Joined: Feb 2000

Hi,

The below url has a working example including the code for "mouseover effect" using Javascript.

http://bignosebird.com/js/mouse.shtml

Hope this helps.

They have: 5,633 posts

Joined: Jan 1970

I never use BODY HEAD or HTML tags...Here is one with a roll-over image:

merlin's picture

They have: 410 posts

Joined: Oct 1999

thanks bubbleman, it works. but only in ie, not in nn (nn is standard in our company Sad ).

anyway, it's exactly what i was looking for!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

does self.src work?

merlin's picture

They have: 410 posts

Joined: Oct 1999

Quote: Originally posted by Mark Hensler
does self.src work?

hm?

well, i realize, i really have to take some time to learn some javascript...

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.