Share on Google+Share on Google+

Change paragraph by clicking button(Toggle effect)

Advertisement
In this tutorial, we will discuss about how to change paragraph by clicking button using jQuery.

Change paragraph by clicking button(Toggle effect)

In this tutorial, we will discuss about how to change paragraph by clicking button using jQuery. In the above example, a button & paragraph is displaying initially .When we click on button , a new paragraph will be displayed and the old one will hidden by this effect.

jqTogglePara.html 

<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.4.2.js"></script>
</head>
<body>
<button>Toggle</button>
<p>Bye</p>
<p style="display: none">Good Night</p>
<script>

$("button").click(function () {
$("p").toggle();
});
</script>
</body>
</html>

OUTPUT

After clicking "toggle " button :

It will change alternately after every click on" Toggle button".

Download Source Code

Click here to see demo

Advertisements

Posted on: July 28, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.