Click event not working after replaceWith
I have the following HTML:
- <div class="content"><button class="showalert">Show Alert</button></div>
<button class="blaat">Test button</button>
With this jQuery code:
- $('.blaat').click(function() {
$('.showalert').replaceWith('<button class="showalert" name="test">Show New Alert</button>');
});
$('.showalert').click(function() {
alert('aaa');
});
When i start with pressing on the 'Show alert' button i get prompted with an alert message like it should.
After that when i press on the other button 'Test button', it replaces the 'Show Alert' button with a new one.
When i press on the 'Show New Alert' button i expect it to also show an alert message. But for some reason it isn't responding to any click() events....
Is this a bug? Or am i doing something wrong??