Hello.
You declare variables on top of your code panel then assign element IDs to these variables inside your event handlers depending on which element was clicked then insert the element IDs to your database collection.
let myElement;
$w("#myElement").onClick((event) => {
myElement = $w("#myElement");
//Add insert code to insert element Ids to the collection
});
Good luck!