jQuery toggle() Method

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Definition and Usage

Suppose there is an image on the website which you want to show only when it is clicked. And when clicked again, you want that image to disappear. Now for that purpose, we can use a toggle method on the image element.

Toggle, in general, means to switch between two different options. Similarly, toggle in jQuery refers to a method which when applied to any element of the website, is used to switch between hide and show property for that element. When the toggle element is executed, it hides the shown element and shows a hidden element.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax

Parameters of toggle in jQuery

There are a few parameters that are used in the toggle in jQuery to give the desired output. However, it is important to note that all these parameters are optional.

ParameterDescription
SpeedDefines the speed of the toggle in jQuery. It can be specified in milliseconds or with simple text values like 'slow' and 'fast'. The time in milliseconds represents the total time for the toggle to occur.
EasingDefines the type of behavior for the toggle. Two options are available: 'linear' (constant speed) and 'swing' (variable speed, increasing in the middle).
CallbackA method executed when the toggle operation has been successfully completed. It allows for additional actions or functions to be triggered after the toggle.
DisplayDescribes whether an element will be visible or hidden. If set to true, the element will be displayed; if set to false, the element will be hidden.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Examples

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

1. Simple Toggle

Now let us see how to implement the toggle method in jQuery in practical terms.

Simple Toggle in JQuery

2. Adding Delay

In the program below, we are applying the toggle method on the heading with the help of a button.

Adding Delay in JQuery

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

3. Adding Delay without Using Numbers

In the program below, we are applying the toggle method on the heading with the help of a button.

Adding delay without using numbers in JQuery

4. Using the Easing Property

In the program below, we are applying the toggle method on the heading with the help of a button.

Using the Easing Property

5. Using Callback

Let us see how we can implement the callback function after the successful completion of a toggle method in jQuery.

Using callback in JQuery

Conclusion

In a nutshell, the toggle method in jQuery is used to provide a toggle effect on the desired element. jQuery also provides various additional options by which we can modify the toggle methods according to our requirements. We have mentioned some frequently used toggle examples above and there are many more possibilities. Now it’s your turn to create some amazing toggling effects!!