I have an onclick event handler function like
onclick="add(this.id,x,y);" , embedded in HTML. The add function, after making its main job, has to overwrite the onclick event handler like:
function add(id,x,y) {
element = getElementById("id");
z = y*x; //just an example
element.onclick = 'add('+id+','+x+','+z+');';
}
So when next time the onclick is called add(id,x,z); should run, but unfortunately it's not working this way. Has anyone a solution for this problem?
thisas a parameter instead ofthis.id; what happens if the element does not have an id? You can then alteradd()as follows:function add(element, x, y) { z = y*x; element.onclick = 'add(this,' + x + ', ' + z + ');';