swap element and add onclick handler