"Table of Contents" web part - How to have expand/collapse buttons? (I can use only CSS/JavaScript/JQuery)

Hi there,
I have a Table of Contents web part which is great. Is there a way so it shows only top level sites and then one can expand or collapse any top level site to see/hide the subsites?
As of now it shows
HR Parent site
- HR sub site 1
- HR sub site 2
IT Parent site
- IT sub site 1
- IT sub site 2
What I want is 
+ HR Parent site
+ IT Parent site
So one can expand or collapse on demand.
Any relevant JS/CSS/JQuery code?
Thank you so much.

Hi,
According to your post, my understanding is that you want to expand or collapse the level site for the table of contents web part.
I have made a simple code demo below to achieve this scenario, you can refer to it.
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
var iconCollapse = "/_layouts/images/collapse.gif";
var iconExpand = "/_layouts/images/expand.gif";
$("div[id='WebPartWPQ2'] li ul").hide();
//ugly way
var $t = $("#WebPartWPQ2 div").children("ul").children("li").children("div");
$t.each(function(){
//console.log($(this).html());
$(this).attr("style", "float: right; margin-right: 297px; line-height: 8px;");
$(this).css("display","inline");
$("<a src=" + iconExpand + "></img>").insertBefore($(this));
$("a[class='min']").click(function()
var img = $(this).children();
//Traverse the DOM to find the child UL node
var subList = $(this).siblings().children('ul');
//Check the visibility of the item and set the image
var Visibility = subList.is(":visible")?img.attr('src',iconExpand):img.attr('src',iconCollapse);
//Toggle the UL
subList.slideToggle();
</script>
Note: Yous should change the Web part ID and the css style to fit your environment.
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support

Similar Messages

  • SharePoint 2013 Table of Contents Web Part

    I have upgraded to SharePoint 2013 and have a table of contents web part that is supposed to display 5 columns. Instead, it is displaying all the sites in one long vertical column. I found the PowerShell script to set the displaycolumns property on the
    web part. However, when I ran the script, this property was already set to 5, yet it is still only displaying one column. I tried adding another table of contents web part and setting the displaycolumns to 5, but that did not work either. How can I make
    this web part to display properly?

    Hi gmchusyr,
    What script did you use for this issue?
    Table of Contents web part's display column is removed from SharePoint 2013 version, it still display in SharePoint 2010.
    Please try to run the PowerShell commands in the TechNet blog below, compare the result.
    Table of Content Web Part: Slightly different in SharePoint 2013 / Online:
    http://social.technet.microsoft.com/wiki/contents/articles/28429.table-of-content-web-part-slightly-different-in-sharepoint-2013-online.aspx
    Best Regards,
    Wendy
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Wendy Li
    TechNet Community Support

  • Table of Contents Web Part

    We have a website that builds a sitemap using the OOTB Table of Contents web part to build a Site Map. The site consists of several subsites and the site map is close but under one particular subsite though the site map shows duplicate links. As
    an example if you look in the page library you see page1.aspx, page2.aspx, page3.aspx and page4.aspx but on the sitemap page it displays:
    SubsiteName
    page1
    page2
    page3
    page4
    page2
    page1
    page3
    Page4
    The repitition isn't in any order either which i have tried to display in my example. Anyone else witnessed this? We have 5 different environments and all are affected in the same way.
    Thanks in advance

    hi
    good that you found workaround, but I would anyway add few words here which may help to troubleshoot original problem: in this case it is worth to check navigation settings of the problematic site. There may be some headings and links added manually, which
    cause this behavior.
    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

  • Table of contents web part doesn't display all data

    Hi,
    We did a test migration from Sharepoint 2007 to SharePoint 2013. There is a Table of contents web part that is being used to display all of the team sites (more than 25). In the SharePoint 2013 version, the TOC web part is not displaying all of the sites.
    Any ideas of how to make it show all?
    thanks,
    Sherazad

    Hi Sherazad,
    According to your description, my understanding is that you want to display all sites in the Table Of Content web part.
    There is a limitation of the web part, the maximum number of the items displaying in the web part is 50. If you want to display more 50 items, you need to increase or remove the limitation. You need to go to the web.config file of the SharePpoint site, the
    path is C:\inetpub\wwwroot\wss\VirtualDirectories\port number, then find all navigation providers, and add
    DynamicChildLimit attribute to each one . More information, please refer to the link below:
    http://praveenbattula.blogspot.in/2010/11/table-of-contents-web-part-remove-max.html
    Note: before changing web.config, please make a backup for the file.
    After the above, if your issue still exists, please open your site->Site Settings->Navigation, change the value from 20 to [whatever number you want to display] in the “Current Navigation”section. More information,
    please refer to the link:
    http://www.chaitumadala.com/2010/05/sharepoint-2010-table-of-contents.html
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Hiding subsites in Table of Contents Web Part - SharePoint 2010

    I've gone through the normal steps of having the table of contents web part not show a subsite (uncheck the box that says "Show Hidden Sites" as well as hide the site in the global navigation) but for whatever reason, the site I've hidden still
    appears in the table of contents. Is there any way to remove it without deleting the subsite entirely?
    Thoughts?

    Actually, a version of Nate's solution did work for me, it just needs more details.....
    Where you need to check off "Show Subsites" is in the "Current Navigation" section of SiteSettings/Navigation, and then hide the sites from THERE in Navigation Editing and Sorting  (I had already tried it on the Global Navigation side
    and the subsites still appeared in the Table of Contents).  
    For our particular needs, we did NOT want those sites on this root site navigation sidebar as well, so after setting the specific subsites to "Hidden" and saving changes, I went back to SiteSettings/TreeView and unchecked "Enable Quick Launch".
     All appears on the Root Site TOC as desired.
    So, Nate was right about the whole counter-intuitive thing, but no need for custom css or de-activating/activating the publishing  features
    --VS

  • Workflow status web part gives error when going back to previous stage (using GO TO) in Project Server 2013 workflow

    Hi,
    Workflow status web part gives error when going back to previous stage (using GO TO) transition activity  in Project Server 2013 workflow.
    Please guide how to create a workflow which restarts from a desired stage.

    Thanks for your prompt reply....
    It gives following error
    Workflow Status
    This Web Part was unable to load.
    Information that may be useful in solving this problem was written to the Unified Logging Service (ULS) log on the Project Web App with the following ID: e95a9c9c-1f68-90d7-0a3e-5951df70fec6
    For more information, contact your Project Web App administrator.
    what do you mean to restart the Project Server 2013 with different project name, please elaborate....

  • I have an encrypted back up password that I can't remember and I can't back up to icloud. How to I get a backup I can use?

    I have an encrypted back up and can't remember the password. I can't back up to icloud either (maybe because of that). How do I get a backup I can use?

    mwrodd wrote:
    How do I get a backup I can use?
    Either remember your backup password, or you don't.

  • When starting Final Cut Pro 7.0.3 I am all of a sudden getting a message that says "One or more of the scratch disks don't have read/ write access" and now the app won't operate - how do I fix this so I can use Final Cut Pro?

    When starting Final Cut Pro 7.0.3 I am all of a sudden getting a message that says "One or more of the scratch disks don't have read/ write access" and now the app won't operate - how do I fix this so I can use Final Cut Pro?

    Glad you found the answer.  But something seems wrong.  FCP should be able to assign the scratch disk to your startup drive.  It's not advisable, but it should be possible.  You might want to try and figure out what's going on before what ever's going on cause other problems.

  • I want to buy the app MUSE. I have two mac. I can use muse in every mac? how can I do?

    I want to buy the app MUSE. I have two mac. I can use muse in every mac? how can I do?

    Mikomejani are you asking how to install Adobe Muse?  If so then please see Install and update apps - https://helpx.adobe.com/creative-cloud/help/install-apps.html.  If not can you please restate your inquiry?

  • How do i know if my macbook can use airplay with apple tv?

    how do i know if my macbook can use airplay with apple tv?

    AirPlay Mirroring needs an Early 2011 or newer MacBook Pro, so your computer supports AirPlay Mirroring. Make a backup, open App Store and purchase OS X Mountain Lion

  • When i plug my ipod into my computer it is not recharging.  The computer doesn't even acknowledge that it is plugged in. Any ideas why? It does have power left so i can use it but i want to recharge it of course.  Any input is appreicated.

    When i plug my ipod into my computer it is not recharging.  The computer doesn't even acknowledge that it is plugged in. Any ideas why? It does have power left so i can use it but i want to recharge it of course.  Any input is appreicated.

    Plug it into the wall using the supplied charger.
    Barry

  • I bought an iPhone 5s in Canada with my company Koodo but now I want to use it in Mexico..How do I get it to work? How do I unlock it so I can use it in Mexico??

    I bought an iPhone 5s in Canada with my company Koodo but now I want to use it in Mexico..How do I get it to work? How do I unlock it so I can use it in Mexico??

    You contact Koodo and ask their terms for unlocking
    According to Apple's latest info they do offer unlocking from their network

  • My Old macbook pro that i bought in 2009. I have broke my screen and havent used it for a while, and now i have found out that i can use a monitor , but i have forgot my password is there any way i can make a new password? Thank you for reading this.

    My Old macbook pro that i bought in 2009. I have broke my screen and havent used it for a while, and now i have found out that i can use a monitor , but i have forgot my password is there any way i can make a new password? Thank you for reading this.

    Have you read for possible solutions over in the "More Like This" thread over here?-----------------------> 
     

  • HT5312 I forget my answer of two security questions, there is a typo error in rescue email address. How to resolve this so that I can use my Apple ID for online shopping?

    I forget my answer of two security questions, there is a typo error in rescue email address. How to resolve this so that I can use my Apple ID for online shopping?

    You won't be able to change your rescue email address until you can answer your questions, you will need to contact Support in your country to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset you can then use the steps half-way down the HT5312 page that you posted from to correct your rescue email address for potential future use

  • I just ordered a macbook air today and need to know if the 128gb SSD is enough space. I presently have a macbook pro and am using only 30gb hard drive space so, the apple rep said 128 is enough as I do not load much pictures or gaming etc. Also is i5 ok.

    I just ordered a macbook air today and need to know if the 128gb SSD is enough space. I presently have a macbook pro and am using only 30gb hard drive space so, the apple rep said 128 is enough as I do not load much pictures or gaming etc. Also is i5 ok.

    Id choose the I5 yes, depends on what your usage is going to be,
    ....your question about "128 gig being enough" begs the question for IDEALIZED USE of your macbook AIr
    In the case of a Macbook Air with ‘limited’ storage on the SSD, this distinction becomes more important in that in an ever rapidly increasing file-size world, you keep vital large media files, pics, video, PDF collections, music off your SSD and archived on external storage, for sake of the necessary room for your system to have free space to operate, store future applications and general workspace.  You should never be put in the position of considering “deleting things” on your macbook SSD in order to ‘make space’.
    *Generally, unless you NEED the data at least once every few weeks or once a month,...it really does'nt NEED to be on the SSD of your Macbook Air.
    Professionals who create and import very large amounts of data have almost no change in the available space on their computers internal HD because they are constantly archiving data to arrays of external or networked HD.
    Or in the case of the consumer this means you keep folders for large imported or created data and you ritually offload and archive this data for safekeeping, not only to safeguard the data in case your macbook has a HD crash, or gets stolen, but importantly in keeping the ‘breathing room’ open for your computer to operate, expand, create files, add applications, for your APPS to create temp files, and for general operation.
    Ive got more APPS than any human should have on my 128gig AIR,..(50 or so),....and 10gig of working data, important files etc etc.
    Still have 82gig available....... the entire point is that someone shouldnt consider the Air a "storage device" for tons of pics, music, vids, etc.
    *Never consider any computer a data storage device at any time under any circumstance, rather a data creation, sending, and manipulation device. Anyone who thinks data is safe on any computer, even copied upon multiple partitions is making a mistake that will, without fail, strike.
    For needs of packing around a LOT of "big data" with your Air in its case..., get a nice 1TB HD for $70, or even a 2TB drive not much bigger.
    Perfect 2TB HD, very slim, the "little giant"   made by Toshiba (have several of these) $119
    http://www.amazon.com/Toshiba-Canvio-Connect-Portable-HDTC720XK3C1/dp/B00CGUMS48 /ref=sr_1_4?s=electronics&ie=UTF8&qid=1379182740&sr=1-4&keywords=2tb+toshiba
    *This one is the BEST  external HD available that money can buy:
    $75
    HGST Touro Mobile 1TB USB 3.0 External Hard Drive
    http://www.amazon.com/HGST-Touro-Mobile-External-HTOLMX3NA10001ABB/dp/B0062FZ2WS /ref=sr_1_1?s=electronics&ie=UTF8&qid=1379185002&sr=1-1&keywords=hitachi+extern a l+hard+drive

Maybe you are looking for

  • Text from another source?

    I want to create a flash website that has some text content (and other content also), so I want that the text would update based on a text file. I really don't know if it is possible, maybe there are other posibilities to make the text update from a

  • I cannot access gmail

    I can access gmail from IE and Chrome. Not from Mozilla. I tried the cookies thing and the safe made thing and still get this. The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a w

  • Cannot install adobe reader on windows 7

    Hi Everyone, I have been trying to install Adobe Reader X on my computer but everytime it finishes the download and I click on the run, the cursor will have the circle next to it saying that it is loading but it will eventually stop and nothing will

  • How can i create my own t-code

    hi , how can i create my own t-code with a specified applications? may i know the t-code for create a t-code Edited by: amarnath popuri on Nov 24, 2008 10:53 AM

  • How to install Leopard without a CD-ROM

    I bought leopard, but my CD-ROM has a part that is jammed. I want to know get leopard without using a CD-ROM. I took it to the apple store but they wouldn't fix it even with applecare, saying that it was physically broken. I don't want to know how to