Is there a way to change the action performed on a particular event of a particular element:
document.getElementById(‘id’).ONCLICK
I’ve tried the above code and it doesn’t seem to work. Or am I doing something wrong…
Is there a way to change the action performed on a particular event of a particular element:
document.getElementById(‘id’).ONCLICK
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:
document.getElementById(‘id’).onclick
but remember… javascript’s onclick is an actual event meaning just assigning it like this:
document.getElementById(‘id’).onclick=“dosomething()”;
will NOT work if you want to do something like that use:
document.getElementById(‘id’).onclick=Function(“dosomething()”);
-ALL
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
};