title: How can I execute an external function when an element is clicked?
body: <p>I'm trying to execute an external function on click of a DOM element without wrapping it in another function.</p>
  
  <p>Say I have a function called <code>sayHello()</code>, as follows:</p>
  
  <pre><code>function sayHello(){
    alert("hello");
  };
  </code></pre>
  
  <p>To execute it on click, I currently have to do this:</p>
  
  <pre><code>$("#myelement").click(function(){
    sayHello();
  });
  </code></pre>
  
  <p>Notice I am forced to wrap the single function call in yet another function.
  What I am trying to do is something like this</p>
  
  <pre><code>$("#myelement").click(sayHello());
  </code></pre>
  
  <p>Except that simply doesn't work.
  Can I avoid wrapping the single function call in another function in any way?
  Thanks!</p>
  
  <p>.</p>
  
  <p>Additional information:
  How would I achieve the same thing when I need to pass parameters to the function?</p>
  
  <p>..</p>
  
  <p>Additional information:
  Like Chris Brandsma and Jani Hartikainen pointed out, one should be able to use the bind function to pass parameters to the function without wrapping it in another anonymous function as such:</p>
  
  <pre><code>$("#myelement").bind("click", "john", sayHello);
  </code></pre>
  
  <p>with <code>sayHello()</code> now accepting a new parameter, as such:</p>
  
  <pre><code>function sayHello(name){
    alert("Hello, "+name);
  }
  </code></pre>
  
  <p>This, unfortunately, does not seem to work... Any ideas?
  The Events/bind documentation is located <a href="http://docs.jquery.com/Events/bind" rel="noreferrer">here</a>
  Thanks!</p>