using Javscript on a webpage
Javascript's primary reason to exist was to allow website developers to execute behaviors based on user input, like clicking.
Events are bound to objects using handlers like “onclick()”, “onhover()”, etc. and are typically embedded on the page, or in an external .js file
Following will cause an alert when clicked, and prevent returning so you don't actually follow the link:
The code:
<a href="#" onclick="alert('thanks for the click'); return false;">click me</a>
More complex logic can be achieved in similar fashion:
- hide/show the table of contents
- flash an informative message
- animate something
- make AJAX requests to get more data
It's advisible to look into using a Javascript library like jQuery or Prototype when things start getting hairy! Save yourself some typing.