document.getElementById('id').ONCLICK ???

Is there a way to change the action performed on a particular event of a particular element:


I’ve tried the above code and it doesn’t seem to work. Or am I doing something wrong…

yes you are… javascript is casesensitive… it needs to be:


but remember… javascript’s onclick is an actual event meaning just assigning it like this:


will NOT work if you want to do something like that use:



There is no need to use the function constructor. It is not recommended to use it, since it basically needs to do an eval. Which is slow.

// Assign a function to deal with the onclick event:
document.getElementById('id').onclick = doSomething;

// or use an anonymous function:
document.getElementById('id').onclick = function() {
    // do magic