javascript for expand and colapse

Posted on 2009-04-20
Last Modified: 2012-08-13
iam using C# code,i want javascript for expand/colapse , when we click on an item that will be expanded and other all expanded item should be colapsed, only the clicked item should be expanded.please help me how can i do this??
Question by:ninusajil

    Expert Comment

    here in this ajax will be used, you can get its complete tutorial on microsoft website

    just type ajax videos in google and u will find the first link darkened. please go there.

    Author Comment

    sorry, i not like to use ajax for this, will u pls help using javascript for this
    LVL 9

    Expert Comment


    Accepted Solution

    u can find the script of collapse and expand on

    just search here in this site, i am sure u will get it.
    LVL 9

    Expert Comment

    by:Sreedhar Vengala
    You should be able to expand on this:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <link href="style.css" rel="stylesheet" type="text/css" />
    <title>Expand / Colapse Div</title>
    <script type="text/javascript">
    function toggle2(id, link) {
      var e = document.getElementById(id);
      if ( == '') {
    = 'none';
        link.innerHTML = 'Expand';
      } else {
    = '';
        link.innerHTML = 'Collapse';
    <body bgcolor="Background">
    <a href="#" onclick="toggle2('content', this)">Collapse</a>
    <div id="content" style="display:none">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc fermentum.

    Open in new window

    LVL 2

    Expert Comment

    expand a collapse what?

    Author Comment

    sorry for the late respose, i am  not well for some days.....

    i tried this

    this is working but when i expand any one and goes to some other page and returns back the expanded item expand as it is not colapsing
    i want collapse all when i took that page

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
    Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now