Jump to content

jQuery slideToggle hide other elements


kartul

Recommended Posts

Hey all

I want to make that when I click on login, the login div appears (and if registration div is visible, hide it first) and vise-versa.

 

here is my code so far:

    <script>
    
    $(document).ready(function() {
        $("#tLogin").click(function() {
            $("#login").slideToggle("slow");
        });
        $("#tRegister").click(function() {
            $("#register").slideToggle("slow");
        });
    });
    
    </script>

    <div id="pHeader">
        <div id="login">
            <form action="index.php" method="POST">
                <p>
                    <label for="username">Username</label>
                    <input type="text" name="username" id="username">
                </p>
                <p>
                    <label for="password">Password</label>
                    <input type="password" name="password" id="password">
                </p>
                <p>
                    <input type="submit" name="login">
                </p>
            </form>
        </div>
        <div id="register">
            <form action="index.php" method="POST">
                <p>
                    <label for="username">Username</label>
                    <input type="text" name="username" id="username">
                </p>
                <p>
                    <label for="password">Password</label>
                    <input type="password" name="password" id="password">
                </p>
                <p>
                    <label for="password">Password</label>
                    <input type="password" name="passwordCheck" id="passwordCheck">
                </p>
                <p>
                    <label for="email">E-mail</label>
                    <input type="email" name="email" id="email">
                </p>
                <p>
                    <input type="submit" name="register">
                </p>
            </form>
        </div>

Link to comment
Share on other sites

Try this:

 

    $(document).ready(function() {
        $("#tLogin").click(function() {
            $("#login").slideToggle("slow");
            if (("#register").is(":visible")) {
                $("#register").hide();
            }
        });
        $("#tRegister").click(function() {
            $("#register").slideToggle("slow");
            if (("#login").is(":visible")) {
                $("#login").hide();
            }
        });
    });

Link to comment
Share on other sites

  • 5 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.