Slide toggle with jQuery

Marko Krstić
29 Nov 2019

Expand object with click on the button.

The trigger is class on the object that will start the animation. Assign the class to the object that should be animated and replace 300 (milliseconds) to what you prefer

$( ".trigger" ).click(function() {
	$( ".toggled-object" ).slideToggle(300);
});

Wrap this with document ready code.

(function($){
    $(function() {
	// Your custom code here
		
    });
})(jQuery);

The final code should look like this

(function($){
    $(function() {
		$( ".trigger" ).click(function() {
			$( ".toggled-object" ).slideToggle(300);
		});
		
    });
})(jQuery);

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy