How to use jQuery.toggle() method in jQuery?

jQueryWeb DevelopmentFront End Technology

The toggle() method toggles displaying each of the set of matched elements.

Example

You can try to run the following code to learn how to work with jQuery.toggle() method:

Live Demo

<html>

   <head>
      <title>jQuery toggle() method</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       
      <script>
   
         $(document).ready(function() {

            $("#toggle").click(function(){
               $(".target").toggle( );
            });
         });
           
      </script>
       
      <style>
         p {
             background-color:#bca;
             width:200px;
             border:1px solid green;
         }
      </style>
   </head>
   
   <body>

      <p>Click on the following button:</p>
      <button id = "toggle"> Toggle </button>

      <div class = "target">
         <img src = "../images/jquery.jpg" alt = "jQuery" />
      </div>
 
   </body>
</html>
raja
Published on 22-Dec-2017 13:49:17
Advertisements