I have found a few posts that seem similar to what I need, but none seem to solve my problem.
I have a set of variables containing data arrays. For example:
var data1 = [1,2,3,4,5];
I have elements on the page with id’s that match those variable names.
<li id="data1">Data 1</li>
I want to be able to click on the <li> element, and call the associated variable.
How do I use the variable data1 by clicking on the element with an id of data1…?
As a basic example, let’s say I want to alert the contents of the data1 array.
I start with something like this:
$('li').click(function() {
dataID = $(this).attr('id');
alert( ...? ); // <- how do I get the contents of the variable data1 now that I know the clicked element's id was 'data1'?
});
If you store the variable on an object, you can reference it easily using array notation.