I\'m trying to modify all links on a page so they perform some additional work when they are clicked.
A trivial approach might be something like this:
You need to create a closure to preserve the original onclick
value of each link:
Hi
There
Note that this implementation only performs the new onclick handling if the original onclick handler returns true. That's fine if that's what you want, but keep in mind you'll have to modify the code slightly if you want to perform the new onclick handling even if the original handler returns false.
More on closures at the comp.lang.javascript FAQ and from Douglas Crockford.