javascript: How to assign a function to an element.
- by Tom
Hi,
Here's what I want:
I have an element in my html code, and I want to assign a function to the onClick event, depending on some conditions to be known down the road.
For example
<a href="" id = "element"><img .....>
//other code
</a>
Then I want to do something like this
<logic:equals some_condition>
<script>
var e = document.getObjectById("element");
e.onClick = my_function();
</script>
</logic>
But I cant get it working.
Is there any special syntax?
I've tried with
e.onClick = my_function;
e.onClick = function(){my_function();}
Sadly i'm in IE 6.
Thanks in advance.