Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery toggle( ) Method

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 43
    Comment on it

    This method is used to work with multiple functions i.e when you click on selected element first function will be fired and when you click on that selected element second function will be called and so on.
    Syntax :

    $(selector).toggle(function)
    

    Parameter :
    function : A function will fired every time on click the selected element.

    HTML Code :

    <html>
    <head>
    </head>
    <body>
    <p>Click me.</p>
    </body>
    </html>
    

    jQuery Code :

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
        $("p").toggle(
            function(){$("p").css({"color": "red"});},
            function(){$("p").css({"color": "blue"});},
            function(){$("p").css({"color": "green"});
        });
    });
    </script>
    

    Output :
    Click me // when you click first time its color changed to red , on clicking second time its color change to blue, on third time it's color changed to green.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: