I saw this question and the first answer works great for the question asked... but what if I want to re-use the code over and over with different named elements?
Let me be specific.
Throughout my code (multiple pages on the site all calling same file.js) I want to have various internal "links" that right now I have written as:
<a onclick="testFunction('targetA');">test A</a>
<a onclick="testFunction('targetB');">test B</a>
And that calls the javascript accordingly. The advantage to this is that the same JS is used over and over without the need to write one for each "target". The disadvantage, besides the fact I have to type that mess above each time, is that according to that guy's answer it isn't the right way to do things.
So is there a "right way" where I can do something like this (realize this is pseudo-code):
<a id="test.A">test A</a>
<a id="test.B">test B</a>
And NOT have to explicitly define test.A vs test.B (vs C, D, E...) in the JS file? For example, the JS could be registered to "#test" but parse out the .X and act on that as a variable?
Or????