Effet jQuery - méthode toggle (switch)

La description

le toggle( switch )bascule de méthode affichant chacun des éléments correspondants en fonction du paramètre passé Si le paramètre true affiche tous les éléments, false masque tous les éléments.

Syntaxe

Voici la syntaxe simple pour utiliser cette méthode -

selector.toggle( switch );

Paramètres

Voici la description de tous les paramètres utilisés par cette méthode -

  • switch - Un interrupteur pour activer l'affichage.

Exemple

Voici un exemple simple montrant l'utilisation de cette méthode -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {

            $("#false").click(function(){
               $(".target").toggle(false);
            });

            $("#true").click(function(){
               $(".target").toggle(true);
            });
				
         });
      </script>
		
      <style>
         p {background-color:#bca; width:250px; border:1px solid green;}
      </style>
   </head>
	
   <body>
      <p>Click on any of the following buttons:</p>
		
      <button id = "false"> False Switch </button>
      <button id = "true"> True Switch </button>

      <div class = "target">
         <img src = "../images/jquery.jpg" alt = "jQuery" />
      </div>
   </body>
</html>

Cela produira le résultat suivant -

jquery-effects.htm