You could replicate your code for the second link. Or you could create a common function that performed the steps and tell it what file and element to work with for each click. Or you could add attributes to the links to identify the file and target element and use those in a common click handler.