jQuery toggle() Method

jQuery toggle() method display or hide the selected elements. jQuery toggle() method actual set in-line CSS property either style="display: none;" or style="display: block;" on selected element. And selected elements will be hide/show immediately with no animation.

jQuery toggle() method toggle between hide() and show() for the selected elements.


This syntax represent to the toggle() method

$(selector).toggle( duration, callback );
Parameter Type Description
duration Number
Required. Accept string or number that determining how long the animation will run.
default value is 400
Accepted values:
  • Predefined duration ("slow", "normal", "fast")
  • number of milliseconds (3000, 1000)
callback Function Optional. A function to call once the the animation is complete.


Here, in this example show toggle() effect on selected elements when click on button.

<!DOCTYPE html>
  <title>jQuery toggle() method</title>
  <script src="jquery-latest.min.js"></script>
    $(document).ready(function() {
      $("#toggle").click(function () {
  <style type="text/css">
    p {
  <button id="toggle">Hide/Show</button> 
  <p style="">This paragraph will hide/show</p>

Run it...   »