jQuery function not working in WordPress but works in jsfiddle

There are a few possible culprits for your issue:

  1. If the script file for this function is loaded before jquery is loaded, you may see a jquery is not defined error in the debugger/console. If that’s the case, just change the order of your script loading to ensure the dependencies are loaded first.

  2. If the function is being added directly into the wysiwyg body area or a template file and not a js file for the theme, you may need to call jQuery.noConflict(). See the jQuery documentation about when and why you would use this.

Also worth noting, you have a typo in the javascript code you posted here. There shouldn’t be a period/dot in front of the class name being passed to addClass or removeClass