I have tried the following code. When the user clicks on any paragraph then this paragraph must be stored into a javascript array. If I clicked another paragraph then it must also stored into any array with out losing the last one.
function makeSelection(e) {
var test = [];
for (var i = 0; i < e.children[0].length) {
test.push(test[i])
}
console.log(test)
}
<a href="#" onclick="makeSelection(this)">
<p>This is p1</p>
</a>
<a href="#" onclick="makeSelection(this)">
<p>This is p2</p>
</a>
<a href="#" onclick="makeSelection(this)">
<p>This is p3</p>
</a>
;i++Also you should have a as a child of the a and not the other way around. Voting to close since It's caused by a typo or problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers