We have multiple links enclosed in a block:
<div>
<a href="#" id="john">text</a>
<a href="#" id="mary">text</a>
<a href="#" id="emma">text</a>
</div>
Each link has a unique id.
I am attempting to create separate arrays in javascript for each link inside this block. The challenge lies in the dynamic nature of the ids, which change constantly.
The desired output should be like this:
var john = [];
var mary = [];
var emma = [];
The id of the link corresponds to the name of the new array.
1) How can I achieve this coding task?
2) How can I use the id of the link to reference an array? For instance, after creating the arrays, in javascript I want to do something like
$(this).attr("id").push("text"); // when hovering over a link
This code snippet does not work as intended. What is the correct method to accomplish this?