javascript - How can I execute an external function when an element is clicked? -


I am trying to execute an external function at the click of a DOM element without wrapping it in any other function.

Say that I have the function as halo () , as follows:

  say the function hello () {alerts (" Hello "); };  

To execute it on click, I have to do this now:

  $ ("# myelement"). Click (function () (sayHello);});  

Notice I have been forced to wrap a function call in another function so far. What I am trying to do is something like this

  $ ("# myelement"). Click (say hello ());  

Except that it just does not work Can I save a function call in any other way from wrapping in any way? Thanks!

Additional information: How do I get the same thing when I need to pass the parameters of the function?

..

Additional information: Like Chris Brandsma and Jani Hartikanen, to pass the parameters of the function in any other anonymous function to use the Tomb Function Should be enabled in:

  $ ("#myelement"). Dam (say "click", "john", halo);  with   

say hello () is accepting a new parameter now, like:

  say the function (hello ) {Warning ("hello," + name); }  

This, unfortunately, does not seem to work ... any thoughts? Thanksgiving event / bind documentation is located!

To raise you with a question. / P>

Obviously, you need to work it like this:

  $ ("# myelement"). Click (say hello);  

By clicking on it you can actually implement the method instead of sending the method to the click handler.

If you need to pass the data then you can call the method like this:

  $ ("myelement"). Click (function (say hello ("tom");});  

or you can pass data through the function

  Say hello (event) {warning ("hello", + event.data);} $ ("# myelement"). Bind ("click", "tom", say hello);  

or you can retrieve data from the clicked element

  $ ("# myelement"). Click (function () {sayHello ($ (this) .attr ("HasData");}).  

Hope that helps.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -