Site logo

Archived topic

Adding CSS -JS animation on click

4 replies · Started by Alessandro on May 4, 2021

Viewing posts 1–5 of 5

Hello,
i'm trying to integrate this code:https://codepen.io/thetallweeks/pen/boinE here: https://www.autozitra.it/chi-siamo-vendita/
I put the css code in the style.css of the child-theme.
Then the html code into the page just before the footer.https://www.autozitra.it/chi-siamo-vendita/ : you will see a square and a button "click me".
Then the Js code in an element hook (wp_head) inside tag <script> </script>, execute php checked on.
it doesn't work... where am i wrong?

Thank you very much...

Hi there,

1. so the JS you have is this:

$("#button").click(function() {
  $('.transform').toggleClass('transform-active');
});

But WordPress doesn't accept the $ variable for jquery it has to be predefined. Change the code to:

jQuery("#button").click(function() {
  jQuery('.transform').toggleClass('transform-active');
});

2. That code should be executed after the Button is loaded.
Use the wp_footer hook instead.

Hi David,
thank you very much, it works perfectly...i love Generatepress and its team!

resolved

Glad to be of help!

This archived topic is closed to new replies.