Function call in jQuery with click ()

In the code below, why does the open function work, but the close function does not work?

$("#closeLink").click("closeIt"); 

How do you just call a function in click() instead of defining it in the click() method?

 <script type="text/javascript"> $(document).ready(function() { $("#openLink").click(function() { $("#message").slideDown("fast"); }); $("#closeLink").click("closeIt"); }); function closeIt() { $("#message").slideUp("slow"); } </script> 

My HTML:

 Click these links to <span id="openLink">open</span> and <span id="closeLink">close</span> this message.</div> <div id="message" style="display: none">This is a test message.</div> 
+45
function jquery
Jan 15 '09 at 16:19
source share
1 answer
 $("#closeLink").click(closeIt); 

Suppose you want your function to pass some arguments to it, i.e. closeIt(1, false) . Then you must create an anonymous function and call closeIt from it.

 $("#closeLink").click(function() { closeIt(1, false); }); 
+115
Jan 15 '09 at 16:21
source share
— -



All Articles