I have a very simple JS code that only does one thing, which is to toggle anopenclass on a specific element on the page. The problem is, I have 4 duplicate.clickSlideelements and.sub_menuelements, and when I click on one of them to trigger the tag, all the elements getopenkind. Only one of the focused elements should get theopenclass.
My best guess is that somethingthisis 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:
jQuery(document).ready(function($) { $(".clickSlide").click(function(){ $(this).children(".sub_menu").toggleClass("open"); }); });