Consider following HTML snippet:

    <input type="button" value="Button 1" />
    <input type="button" value="Button 2" />
    <input type="button" value="Button 3" />
and jQuery code snippet:

        $(document).ready(function() {
            $("[type='button']").each(function(i) {
                for (var j = 0; j < i; j++) {
                    $(this).click(function() {
                        alert(this.value);
                    }).slideToggle(300);
                }
            });
        });
What will happend after clicking on button3?
Explanation
We will have two buttons after the page loading - slideToggle() will hide button2. On click at button3 the allert box will show the value of button3 two times.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
JavaScript quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes