-1

I have:

<script>
$(document).ready(function(){
    $('#open').toggle(
        function(){
        $('#login form').slideDown(300);
        $(this).addClass('close');
    },
        function(){
            $('#login form').slideUp(300);
            $(this).removeClass('close');
    });
});
</script>

<div id="login">
        <p id="open">Login</p>
        <form>
            <p>
                <label for="username">Username:</label>
                <input type="text" name="username" id="username">
            </p>
            <p>
                <label for="password">Password: </label>
                <input type="text" name="password" id="password">
            </p>
            <p>
                <input type="submit" name="button" id="button" value="Submit" >
            </p>
        </form>
    </div>

With the new versions of jQuery. What could be an alternative way of achieving this same behavior?

Robert
  • 10,126
  • 19
  • 78
  • 130

2 Answers2

1

In this case you can use click() handler along with slideToggle() and toggleClass()

$(document).ready(function () {
    $('#open').click(function () {
        $('#login form').slideToggle(300);
        $(this).toggleClass('close');
    });
});

Demo: Fiddle

But if you are looking for a general replacement, you can have a look at the different toggleClick() methods like this one

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

What you could do:

$(document).ready(function(){
    var clicks = 0;
    $(element).event(function(){
        clicks++;
        if (clicks % 2) {
            //Some stuff to do if odd
        } else {
            //Some stuff to do if even
        }
    });
});