Skip to content

[Bug]: Modal not placed by default on body based on documentation #841

Closed

Description

@tobidemski

Expected Behavior

Modal is injected to the body element by default if no root is set.

https://cookieconsent.orestbida.com/reference/configuration-reference.html#root

Root (parent) element where the modal will be appended as a last child.

Type: string | HTMLElement
Default: document.body

Current Behavior

Modal is set as a sibling next to the body tag.

Steps to reproduce

Use default configurations for the cookieconsent

Proposed fix or additional info.

Workaround:
Set root: 'body' to get the desired result

Additional info:
#816 provided some changes how the modal is injected. Previously (I upgraded from 3.1.0) my modal was always injected at the end of the body tag. After the upgrade I noticed the modal was next to the body tag as a sibling. After I set the root property in the cookie settings to 'body' I got the old behavior.

https://github.com/orestbida/cookieconsent/pull/816/changes#diff-04fdf1645858c3719e6ef4118dfbec273b5ed23bb5a1ca851f184598b1eafe6bR33
_dom._rootEl is set with a fallback value of doc.documentElement if no root is set in the config.

https://github.com/orestbida/cookieconsent/pull/816/changes#diff-59bda3abc027da2d4d0aa42c930219f8cc132a81b492ef7fed886a492737a7aaR20
dom._rootEl is now the doc.documentElement by default and previously it was document.body if no root was set.

Version

3.2.1

On which browser do you see the issue?

Chrome

Activity

  1. added
    bug
    on Nov 2, 2026
  2. added
    triage
    on Nov 2, 2026
  3. removed
    triage
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions