twitter/bootstrap — Issue #391: Opening and closing a modal twice removes underlying link 
Author: billsaysthis
Created: 2011-10-08 18:10:19+00:00
State: open

Below is my HTML and related JS. Clicking the image loads the modal properly; first time I click to close the modal the underlying page is as expected. However after opening and closing the modal a second time the image is no longer present on the main page.

I tried both versions of the JS function and several similar variants but always have the same results, or the image disappears on first time closing the modal.

If the link to open the modal is a text link I don't see the problem. But the requirement is for an image link ;)

Not sure if this is incorrect coding on my part or a bug in the JS.

```html

```
```javascript
$(function() {
$('.modalImage').click(imageModal);
}

// version 1
var imageModal = function() {
var newSrc = $(this).find('img').attr('src').replace('.png','-mv.png');
var mo = '#'+$(this).data('controlsModal')
$(mo).find('.modal-body img').attr('src', newSrc);
$(this).modal();
}

// version 2
var imageModal = function() {
var self = this;
var old = $(this).find('img').clone();
var oldSrc = $(this).find('img').attr('src');
var newSrc = oldSrc.replace('.png','-mv.png');
var mo = '#'+$(this).data('controlsModal')
$(mo).find('.modal-body img').attr('src', newSrc);
$(this).modal().hidden(function() { $(self).append(old); });
}