Custom jQuery doesn't fire (but it does using chrome console)

Hello,

My custom jQuery code doesn’t work when I publish my website.
I tried adding theses scripts. But it does not work.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>

If I copy/past my jQuery code into the Chrome console, it work the right way.
Here’s the jQuery code.

<script>
$('input:radio').change(function(){
   if($(this).is(':checked')) {
       $(this).parent().addClass('selected'); 
       $('input:radio').not(':checked').parent().removeClass('selected');
   }
 });
</script>

I can also see that my code is in the page code.

Thanks for your help.
Théo.


Here is my site Read-Only: LINK

Alright. Solved.

If someone encounter the same problem, here’s the solution.
I was trying to select and element and place the code in the head tags. When the code is loaded, the content of the body is not.

You need to place the code at the end of the page.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.