function call

L

lynch

How to call a javascript functio, but not from event (onClick, onChange,
etc.) but juist from code (if something than some thing; else call a
javascript function).
 
P

Peter Michaux

How to call a javascript functio, but not from event (onClick, onChange,
etc.) but juist from code (if something than some thing; else call a
javascript function).

<script type="text/javascript">
function myHandler() {
alert('hi');
}
</script>

<p id="foo" onclick="myHandler()">click me</p>

Then anywhere you want you can do this

<script type="text/javascript">
myHandler();
</script>

This is how I would probably share a handler.

You could access the onclick property of the paragraph above but that
does not seem like an good solution to me.

document.getElementById('foo').onclick();

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,795
Messages
2,569,643
Members
45,356
Latest member
deepthi.kodakandla

Latest Threads

Top