I have the need to show different information depending on which link has been pressed (a list of clients as it happens). I have it working for 2017 and I could repeat the function for every other year but is it possible to pass the year as a parameter to an anonymous self-invoking function so I only have the function code once?
Edit: Of course, there may be a better way of achieving what I’m after…
Instead of iterating over those spans, you might store the target which should be shown in a data attribute (say data-show="#c2017" etc.), and bind only one event listener to the parent element. Then you can check if the event.target has such a data attribute, and show the corresponding div, like e.g.
I have updated my Codepen https://codepen.io/gandalf458/pen/ygNYRr and have made the links appear like a href links. It works fine but I want to make one addition, to change the colour of a “link” when it is effectively active.
The line I have added is clearly not what I want but it proves part of the concept. Instead of getElementById('c2016x') I want to select the element with the same id as the data-show value but without the # and with x on the end - and this is where I am flummoxed.