The behavior is caused by a conflict in the code. When the close button is clicked you both create and remove a new
//This line removes the .media-list-display div when
//the close button is clicked
//This line adds a new .media-list-display div when any `<a>`
//inside .media-list is clicked.
The problem is that the close button is also an
.media-list so when it is clicked it triggers both events creating an endless loop of removing and creating.
Check this link out with alerts on the conflicting parts.