October 3, 20179 yr What I want is to click any <li> in a <ul>, and then affect ALL elements with the same class on the entire page. $("anyclass").click(function(){ $("anyclass").hide(); }); I don't want to manually enter the element classes, as the client can add additional items to the list and their class is a random ID. I feel like it should be a very small piece of jquery but I can't think for life of me.
October 3, 20179 yr Author Just a little more info. $(".icon.id-55").click(function(){ $(".id-55").toggleClass("active"); }); When you click the .icon with .id-55, it also toggles the .active for a panel below with the .id-55 class. I essentially want to replace the id-55 with id-n Any thoughts?
October 3, 20179 yr Something like this https://jsfiddle.net/trpfq3m5/? It's a little fragile, because it depends on the numbered class being after the first class (classList[1]). I still think it's better than doing it dynamically with a count, because they tend to always be incorrect, especially if the class names have been generated by a CMS. edit: updated jsfiddle example Edited October 3, 20179 yr by Jack
October 3, 20179 yr Author Something like this https://jsfiddle.net/trpfq3m5/? It's a little fragile, because it depends on the numbered class being after the first class (classList[1]). I still think it's better than doing it dynamically with a count, because they tend to always be incorrect, especially if the class names have been generated by a CMS. edit: updated jsfiddle example Thank you Jack this seems to do what I want. I'll try applying it tomorrow. Just out of curiosity, what does the + el do? ('.panel-' + el)
October 3, 20179 yr Thank you Jack this seems to do what I want. I'll try applying it tomorrow. Just out of curiosity, what does the + el do? ('.panel-' + el) el is just a variable (short for element) that contains the number part of the class. The plus is concatenating both the class name (panel-) and the number together.
Create an account or sign in to comment