I have a very simple JS code that only does one thing, which is to toggle anopen
class on a specific element on the page. The problem is, I have 4 duplicate.clickSlide
elements and.sub_menu
elements, and when I click on one of them to trigger the tag, all the elements getopen
kind. Only one of the focused elements should get theopen
class.
My best guess is that somethingthis
is missing in the JS. But I'm open to solutions to this problem!
jQuery(document).ready(function($) { $(".clickSlide").click(function() { $(".sub_menu").toggleClass("open"); }); });
So the solution (based on Anass Kartit's answer) is this: