jQuery Effects: hide(), toggle(), fadeIn(), fadeOut(), and fadeToggle()

jQuery Effects tutorial featuring hide(), toggle(), fadeIn(), fadeOut(), fadeTo(), and fadeToggle() methods.

Post Date: March 7, 2020
Last Updated:
November 12, 2026

Introduction

jQuery is a popular JavaScript library that simplifies HTML document manipulation, event handling, animations, and other web development tasks. One of its useful features is jQuery Effects, which allows developers to add interactive visual effects to HTML elements.

jQuery provides several built-in effect methods that can be used to show, hide, and animate HTML elements without writing complex JavaScript code.

In this blog, we will explore some commonly used jQuery Effects methods, including hide(), toggle(), fadeIn(), fadeOut(), fadeTo(), and fadeToggle(), with syntax and practical examples.

1. jQuery hide() Method

The hide() method is a built-in jQuery effect method used to hide the selected HTML elements. When this method is executed, the selected element gradually disappears if a duration is specified.

Syntax:

$(selector).hide(duration, easing, callback);

Parameters:

  • duration: Specifies how long the hiding animation takes (milliseconds).
  • easing: Specifies the speed of the animation at different points.
  • callback: A function executed after the animation completes.

Example:

jQuery hide() method example using HTML and JavaScript code to hide a paragraph element when the user clicks a button, demonstrating jQuery hide effects.

Explanation:

When the user clicks the OK button, the hide() method hides the paragraph element with a 500-millisecond animation.

Before clicking the button:

Output of a jQuery hide() effect example displaying an OK button and a paragraph containing the text "jQuery effects and method test" before clicking the button.

After clicking the button:

Output of the jQuery hide() method after clicking the OK button, showing that the paragraph text has been successfully hidden.

2. jQuery toggle() Method

The toggle() method is used to switch between showing and hiding selected HTML elements.

If an element is visible, the toggle() method hides it. If the element is hidden, it displays it again.

Syntax:

jQuery toggle() method syntax showing the selector, speed, easing, and callback parameters used to switch HTML elements between visible and hidden states.

Example:

HTML and jQuery code example demonstrating the toggle() method, which shows or hides a paragraph with a 500-millisecond animation when the Toggle button is clicked.

Explanation:

When the user clicks the Toggle button, the paragraph element switches between visible and hidden states using a 500-millisecond animation.

  • First click: Hides the paragraph.
  • Second click: Displays the paragraph again.
  • Subsequent clicks: Continues switching between the two states.

Before clicking the button:

Output of the jQuery toggle() method showing the Toggle button and visible paragraph text before clicking the button.

After clicking the button:

Output of the jQuery toggle() method after clicking the Toggle button, showing that the paragraph text is hidden.

3. jQuery Fade Effects

jQuery provides fade effect methods to control the visibility and opacity of HTML elements.

These methods are useful for creating smooth visual transitions in web applications.

The commonly used jQuery fade methods are:

MethodDescription
fadeIn()Gradually displays a hidden element.
fadeOut()Gradually hides a visible element.
fadeTo()Changes the opacity of an element to a specified value.
fadeToggle()Switches between fadeIn() and fadeOut().

jQuery fadeIn() Method

The fadeIn() method gradually displays hidden HTML elements by increasing their opacity.

Syntax:

$(selector).fadeIn(speed, easing, callback);

jQuery fadeOut() Method

The fadeOut() method gradually hides visible HTML elements by decreasing their opacity.

Syntax:

$(selector).fadeOut(speed, easing, callback);

jQuery fadeTo() Method

The fadeTo() method changes the opacity of the selected HTML element to a specified value.

Syntax:

$(selector).fadeTo(speed, opacity, easing, callback);

The opacity value ranges from 0 (completely transparent) to 1 (fully visible).

jQuery fadeToggle() Method

The fadeToggle() method switches between the fadeIn() and fadeOut() effects.

If the selected element is visible, it gradually fades out. If it is hidden, it gradually fades in.

Syntax:

$(selector).fadeToggle(speed, easing, callback);

Example:

HTML, CSS, and jQuery code example demonstrating the fadeToggle() method to show and hide a blue div element with a fade animation when the Fade button is clicked.

Explanation:

In this example, the fadeToggle() method is applied to the mydiv element.

When the user clicks the Fade button:

  • First click: The blue div gradually fades out.
  • Second click: The blue div gradually fades in.
  • Subsequent clicks: The visibility of the div continues to toggle.

Before clicking the button:

After clicking the button

Conclusion

jQuery Effects provide a simple and effective way to create interactive and visually appealing web pages. Methods such as hide(), toggle(), fadeIn(), fadeOut(), fadeTo(), and fadeToggle() help developers control the visibility and opacity of HTML elements with minimal code.

By understanding these built-in jQuery methods, developers can create smoother user interactions and improve the overall user experience of web applications.

These effects are especially useful for creating dynamic interfaces, interactive buttons, notifications, and animated content sections. Practising these methods with different HTML elements will help developers understand how jQuery animations work in real-world applications.

Frequently Asked Questions (FAQs)

1. What are jQuery Effects?

jQuery Effects are built-in methods used to add animations and visual transitions to HTML elements. They allow developers to show, hide, fade, and animate elements easily.

2. What is the difference between hide() and toggle() in jQuery?

The hide() method hides the selected HTML element, whereas the toggle() method switches between showing and hiding the element based on its current visibility.

3. What is the difference between fadeIn() and fadeOut() in jQuery?

The fadeIn() method gradually displays a hidden element, while the fadeOut() method gradually hides a visible element by changing its opacity.

How to use shift and unshift method in javascript

How to remove & install oracle java [Jdk] in ubuntu 16.0.4

Need Help with JavaScript Development?

Are you looking for professional assistance with JavaScript development, frontend optimization, web application development, or troubleshooting complex JavaScript issues?

Our development team at Pheonix Solutions can help you build, maintain, and optimize modern web applications using reliable development practices.

Get in touch with our team here to discuss your web development requirements.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Scroll to Top