Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




EFFECTS - fadeToggle()


The fadeToggle() Effect is a combination of fade in and fade out effect. i.e. Hides the visible element with fade out effect and if the element is hidden, makes it visible using fade in effect.


Example :



<html>
  	<head>
    	<title> My First Programme </title>
    	
    	<script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script>
  	</head>

  	<body>
    	<h1> JQuery </h1>
    	
    	<p> This is a sentence </p>
    	<button> FadeOut / FadeIn </button> 
	  
      	<script>
      
			$('button').click( function() { 
            	$('p').fadeToggle();
            });
            
      	</script>      
  	</body>
</html>    


Output :




So, in the above example, we have a <p> element,


<p> This is a sentence </p>

And a <button> element,


<button> FadeOut / FadeIn </button>

And on buton click, the JQuery action gets triggered,


$('button').click( function() {
	$('p').fadeToggle();
});

And the fadeToggle() effect gets triggered. So, if the <p> element is hidden, it shows it with faded effect and it the <p> element is visible, it hides it with faded effect.


Similarly, you can use the speed and callback function with fadeToggle() effect.