Drag and drop z order

Hi there

I’m new to the forum so firstly helllo

I’m trying to create a reasonable simple drag and drop animation when the user can grab different coloured square around the stage.

The problem is I want to have the animation so when they click on eack individual square it pops to the top of the z order (the forground) and then on release returns to it’s original postion in the animations z-order (layers)

Any ideas on how to code this ?