I'm using html() to replace content of the element:
<div class="page">
<p>
cheers
</p>
</div>
Jquery:
$('body').on('click', '.page', function() {
var news=Math.floor((Math.random() * 10) + 1);
$(this).html(news);
});
The click events are registered successfully but the when .html() is used the documentation says:
Additionally, jQuery removes other constructs such as data and event handlers from child elements before replacing those elements with the new content.
Why is the behavior not same when using click()?
I've also read on several forums to refrain from using onClick() as it doesn't comprise of modern methods. Is there a way to re-attach the event handlers such that the events register?