How to expanding and collapsing a division using JavaScript/jquery

Posted on 2012-08-31
Medium Priority
Last Modified: 2012-10-02
Dear Experts,

I am new to JavaScript, i want to implement a task that, hide/show or expanding/collapsing a division using javascript / jquery.

Kindly provide the required code.
Question by:prabhualla
  • 2
LVL 10

Accepted Solution

Gregg earned 1500 total points
ID: 38356617
LVL 39

Expert Comment

by:Roger Baklund
ID: 38357013
Plain javascript:

function Toggle(id) {
  var o=document.getElementById(id);
  o.style.display = (o.style.display == 'none') ? 'block' : 'none';

Open in new window


<button onclick="Toggle('TheDiv')">On/off</button>
<div id="TheDiv">Hello!</div>

Open in new window


Author Closing Comment

ID: 38454846
thanks for the solution
LVL 39

Expert Comment

by:Roger Baklund
ID: 38454985
Did you try my code?

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question