jQuery not working on Wordpress page. What am I doing wrong?

I am working from this url.

I have a button (top left in the header called Toggle).

With the script below, I am trying to set it toggle the class .hidden to the id of #sidecontent.

I verified that the script is included in the DOM, and all of the referenced elements are there.

What am I doing wrong?
jQuery(document).ready(function(){ $("#toggle-sc").click(function(){ $("#sidecontent").toggleClass("hidden"); }); });

Looks like you are having some script conflicts. One of your other scripts have unset or otherwise messed with “$” and so your script is throwing errors because you are trying to use $().

Taking your code and making the following changes …

jQuery(document).ready(function($){
  $("#toggle-sc").click(function(){
   $("#sidecontent").toggleClass("hidden");
  });
});

Seems to resolve your problems. Notice how I pass the dollar sign into your ready() callback will resolve the issue. That or just use jQuery instead of the dollar sign. Give that a try. :slight_smile:

Edit: You will see the class toggle on the sidecontent element. I am not sure you have any CSS behind that yet to actually hide the column yet. If you do, it is appearing to not work in hiding the column, but at least the class is being applied.

2 Likes

Okay, that makes sense, but even adding after changing that script, it still doesn’t work…

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