Help // Shortening Javascript
Discussion
SlidingSideways said:
A loop would be the obvious first choice.
Assuming that's JQuery (and I'm a bit rusty here), can you give the elements in each group a different class and select and hide/show based on that?
Yep, I agree. That'd be easier and cleaner. Give each element you want to be hidden or shown together the same class, then you can just select that class with jquery e.g.Assuming that's JQuery (and I'm a bit rusty here), can you give the elements in each group a different class and select and hide/show based on that?
<div id="groupxxfoodyy" class="thingy"></div>
<div id="groupxxfoodyy" class="opposite-thingy"></div>
...
$('.thingy').show();
$('.opposite-thingy).hide();
Then all you have to do is select that class:
But if it helps for future reference, here's an idea of how you can use loops to do things like this:
https://codepen.io/kdurber/pen/WLWJKb?editors=0011
There's a handy function in there for always returning two digit numbers too.

Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff

