Toggle Class &this


Hey Enzo,

Your snippet won't work as it is, you have to declare the $ and fire your code only when the document is ready as follow:

( function( $ ) {
  $( document ).ready( function() {
   $( '#toggle' ).click( function() {
      $( this ).toggleClass( 'active' );
    } );
  } );
} )( window.jQuery );

Please make sure to enqueue your JS file properly.

Happy coding,

Write a reply

Login or register to write a reply, it's free!