If I have the following html:
<html>
<div id="main_content">
<button>click me</button>
<script src="main.js" ></script>
</div>
</html>
And main.js:
$('#main_content').on('click', 'button', function() {
console.log('you clicked');
});
If I do a full page load, then clicking the button only registers one console message. If, however I subsequently re-load main_content's contents via an AJAX request then each button click gives 2 console messages. It will give 3,4,5... messages for each subsequent AJAX load, but always one for a full page reload.
Might someone explain this behavior and suggest possible solutions?