As Stewart Brand famously said, "Information wants to be free." And while generic human greed generally stands in the way of gratis info, JavaScript is a happy exception. The JavaScript code you covet on other people's pages is, in most cases, yours for the taking.
The trouble is, you can't just grab someone else's code, drop it into your Web page, and have it work. You actually have to learn JavaScript, even just the basics. Otherwise you may have trouble making that neat rollover or form checker function the way it should on your own page.
That's where this article comes in. I'll give you just enough JavaScript know-how (and not one bit more) to effectively steal code and still adhere to the first great virtue of the programmer: laziness. By the time you finish with this lesson, you should be able to take someone else's code and use it for your own unique purposes.
But lest I get spammed with hate mail, let me make it perfectly clear
that
"stealing" code is only OK if it's not really stealing. There's lots of
JavaScript out there that was meant to be shared, and
most people will be happy for you to use their code as long as you give
them credit and you use it with your own content (i.e., grabbing code
to make your own buttons into rollovers is good; stealing someone else's
code and buttons and layout is bad). Finally, if you're not sure it's
kosher to use a particular bit of JavaScript, then you need to ask the
original author first.
Aside from making sure your code is moral, you also need to know how to cut and paste text and view source code. You got all that? OK then, let's dig in, starting with script tags.
next page»