Where to put your javascript

This is bad:

<a href="link.blah" onmouseover="soSomeStuff();" onmouseout="stopDoingStuff()">

This is good:

document.getElementById(‘id’).onmouseover = doSomeStuff();
document.getElementById(‘id’).onmouseout = stopDoingStuff();

What is even better is if you keep this in a separate .js file. That way your content should all be in the HTML file, your actions/behaviours should all be in the JavaScript file and your styling should all be in your CSS file. This is logical and good. Do it.

Handy link: Everything you need to know about JavaScript arrays, and then some.

Advertisements

About Mr Chimp

I make music, draw pictures, browse the internet, programme, and make sweet, sweet cups of tea until the early hours.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

2 Responses to Where to put your javascript

  1. Skilldrick says:

    Awesome. Except aren’t you assigning the return value of doSomeStuff() in the good one? I think it should be .onmouseover = doSomeStuff;

  2. Mr Chimp says:

    I’m pretty sure it’s right. I’d check but I’d better do some work…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s