jquery show hide by using jquery toggle method with Div show hide example

jquery toggle()

The toggle() method is used to toggle between show and hide selected HTML elements. If elements are hidden then toggle method will show hidden selected elements and vice versa.

Syntax

$(selector).toggle(speed,callback)

Where

Selector = can be an element like div, p, etc.
Speed = Optional parameter that specifies the hide speed with possible values of

  1. “slow”
  2. “fast”
  3. Or value in milliseconds

Callback = after togle () method is completed, an optional callback function to perform certain action can be given.

Example of toggle() method

In this example we will use jquery hide method to toggle DIV with name “text” after clicking “Toggle Yellow line” button.

Experience this example online


Example with callback function

 

Experience this example online


Also see: jquery show() method | jquery hide() method

Was this article helpful?

Related Articles

Leave A Comment?