tags:

views:

19492

answers:

2

In the code below, why does the open function work but the close function doesn't?

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

i.e. how do you just call a function in click() instead of defining it the in click().

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>Text jQuery Page</title>
    <style type="text/css">
        #message
        {
            width: 400px;
            height: 200px;
            background-color: #eee;
            padding: 10px;
            border: 1px solid #aaa;
        }
        #closeLink
        {
            cursor: hand;
            cursor: pointer;
            text-decoration: underline;
        }
        #openLink
        {
            cursor: hand;
            cursor: pointer;
            text-decoration: underline;
        }
        #control
        {
            margin: 0 0 10px 0;
        }
    </style>

    <script type="text/javascript" src="Scripts/jquery-1.2.6.min.js"></script>

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

        function closeIt() {
            $("#message").slideUp("slow");
        }
    </script>

</head>
<body>
    <div id="control">
        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>
</body>
</html>
+13  A: 
$("#closeLink").click(closeIt);
Tiago
You´re welcome =)
Tiago
A: 

Untitled Page $(document).ready(function() { $('#clickmeupdate').click(function() { alert('Hello world!'); }); }); Click me to update

for anyone who will face