ERIC
ERIC

Reputation: 63

Javascript File Not Functioning in Wordpress w/ Proper Enqueueing in Functions.php

My JS file is being properly called in my functions.php file because there is no error in the console when I inspect element. Why is this js code not running? Do I need to wrap the function? Everything I tired did not work. I am no js expert, but I think this code should work... It worked in my codepen.

Note: I am calling the script in the footer. Should I be calling it in my header since it is for my mobile header menu?

// Mobile Menu

$('.hamburger').on('click', function () {

    $('.main-navigation').toggleClass('open');

});

Upvotes: 0

Views: 26

Answers (1)

Alex Seidler
Alex Seidler

Reputation: 74

It should work fine via the footer. You could try wrapping it in a

$( document ).ready(function() {
   $('.hamburger').on('click', function () {
      $('.main-navigation').toggleClass('open');
   });
});

How are you calling the jQuery? Are you placing it in a shortcode to a function in your functions.php, or directly in a tag inside the footer?

Last question (sorry, i'm new - and thorough): Have you checked your console? Any other Java errors?

  • sorry this is a mess, I am trying to figure out the formatting for answers/comments

Upvotes: 1

Related Questions