?
Solved

How to expanding and collapsing a division using JavaScript/jquery

Posted on 2012-08-31
4
Medium Priority
?
434 Views
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.
0
Comment
Question by:prabhualla
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Gregg earned 1500 total points
ID: 38356617
0
 
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


Usage:

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

Open in new window

0
 

Author Closing Comment

by:prabhualla
ID: 38454846
thanks for the solution
0
 
LVL 39

Expert Comment

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

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