# ToC not working when headers are inside a div?

**URL:** https://meta.discourse.org/t/toc-not-working-when-headers-are-inside-a-div/276615
**Category:** Support
**Tags:** disco-toc
**Created:** [September 6, 2022, 8:35pm UTC](https://meta.discourse.org/t/toc-not-working-when-headers-are-inside-a-div/276615 "2022-09-06T20:35:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Headless](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/headless/32/183495_2.png) [@Headless](https://meta.discourse.org/u/Headless)
#### Post date: [September 6, 2022, 8:35pm UTC](https://meta.discourse.org/t/toc-not-working-when-headers-are-inside-a-div/276615/1 "2022-09-06T20:35:51Z")

</div>

Does the table of contents not work when headers are inside a div? I am trying to make a table of contents with the headers centered but it seems impossible to do.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [September 6, 2022, 9:40pm UTC](https://meta.discourse.org/t/toc-not-working-when-headers-are-inside-a-div/276615/2 "2022-09-06T21:40:30Z")

</div>

I think this was mentioned previously, if I understand it right:

> [@DiscoTOC - automatic table of contents](https://meta.discourse.org/t/discotoc-automatic-table-of-contents/111143/330):
>
> I have posts that have extra DIVs in their bodies. For example, [On Storytelling - Public - Podcaster Community](https://forum.podcaster.community/t/on-storytelling/268) The DIV which triggers the TOC generation is inside a DIV… and TOC notices that. But other headings, inside DIVs, don’t seem to get noticed by TOC. …not the best screenshot. That’s an H2 in an arbitrary/just-for-styling DIV which does not appear in the TOC. …not shown is the \<div that triggers the TOC, which is inside the DIV with the crazy att…

> [@DiscoTOC - automatic table of contents](https://meta.discourse.org/t/discotoc-automatic-table-of-contents/111143/331):
>
> We target the immediate child headings to exclude headings in quotes or oneboxes and other elements in the Table of Contents. Otherwise, we’d have to exclude them individually, which can be tedious.

---

<div class="post-metadata">

### Author: ![Headless](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/headless/32/183495_2.png) [@Headless](https://meta.discourse.org/u/Headless)
#### Post date: [September 6, 2022, 9:52pm UTC](https://meta.discourse.org/t/toc-not-working-when-headers-are-inside-a-div/276615/3 "2022-09-06T21:52:54Z")

</div>

So as far as I can tell basically there is no solution.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [August 25, 2023, 2:35pm UTC](https://meta.discourse.org/t/toc-not-working-when-headers-are-inside-a-div/276615/4 "2023-08-25T14:35:15Z")

</div>

It depends on what you try to achieve with your other HTML content.

I crosspost a potential workaround: [TOC doesn't work when wrapped with HTML tags - #2 by Canapin](https://meta.discourse.org/t/toc-doesnt-work-when-wrapped-with-html-tags/276325/2)
