Skip to content
Advertisement

Multiple Toggles In A Post Loop

I’ve created a simple toggle to reveal and close a food menu. However as this is in a WordPress Loop only the first one works.

I’m guessing because as the page builds itself out there then become multiple ID’s. However I can’t find anyway to tweak the JQuery / JS to not use ID’s.

Any Ideas??

JavaScript

The foodMenuName just swaps ‘open menu’ text to ‘close menu’.

Advertisement

Answer

Consider the following.

JavaScript

This makes use of the class and relative position of the elements. This will Add and Remove the active class to the food-menu upon click.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement