jQuery toggle() animation example

This example shows how to use jQuery toggle() function to show or hide a section inside a paragraph. So by clicking on a button the section will be displayed or hidden using the jQuery toggle() function.

First create the html

 <div class="containingbox">        
        <div class="floatright">
        Here is a new section that appears
Welcome to show/hide section in a paragraph
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
 <button id="clickMe">Click Me</button>

Then create jQuery stuff. Add required jQuery library to the <head/> section.

<script type="text/javascript">
$('#clickMe').click(function() {

Then create css style and put it under <head/> section

<style type="text/css">
float: right;
margin: 0 0 10px 10px;
clear: right;
border-radius: 25px;
border: 1px solid black;

.containingbox p { margin-top: 0;}

  border-radius: 7px;



First time when you run the page

jQuery toggle

When you click on the “Click Me” button
jQuery toggle

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *