javascript: How to assign a function to an element.
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-04-30T13:49:19Z
Indexed on
2010/04/30
13:57 UTC
Read the original article
Hit count: 171
jsp
|JavaScript
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.
© Stack Overflow or respective owner