Site logo

Archived topic

.classList.add()/remove() does not work for "block - hook"

3 replies · Started by Nico on February 10, 2021

Viewing posts 1–4 of 4

I have included three hooks/elements.
1. ShowHide Script for CTA:
Type: hook (->selected: wp_footer), Location: frontpage.

2. "CTA-MENU-Header".
Type: Block - Hook (->selected: generate_menu_bar_items), Location: Frontpage

3. "EmptyHeader"
Type: Header, Location: Frontpage

With the help of element no.2 ("CTA-MENU-Header") I added a CTA button to the header.
Element No.1 ("ShowHide Script for CTA") adds/removes a class "show-cta" for the id "cust-header-btn" when the user scrolls up/down.

But adding the class does not work. According to console output, the class is added, but nothing changes in the html code.

For testing i used the same script. The class was successfully added/removed in the "allgemeines" section.

I have a workaround.
I now make "document.getElementById("primary-menu");" instead of "document.getElementById("cust-header-btn");"
then via classList.add("show-cta") my class "show-cta" is added to the id "primary-menu".

With Css I change the visibility ".show-cta + div >div > a {visibility: visible;}"

Why now at the end the "classList.add("show-cta")" to "document.getElementById("cust-header-btn");" doesn't work, I don't know (see my first post).

If someone has an idea/hint, feel free to tell me. Because this workaround I don't find optimal in case something needs to be changed in the html structure.

Solved. I used the wrong hook. "generate_inside_navigation" is the correct one.

Glad you got it sorted :)

This archived topic is closed to new replies.