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
https://forums.phpfreaks.com/topic/233027-jquery-slidetoggle-hide-other-elements/
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();
            }
        });
    });

  • 5 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.