This is more a learning piece for me around how event listeners bound to jQuery selectors are handled.
So say I have the following code:
<html>
<div class = "one">one</div>
<div class = "two">two</div>
</html>
<script>
$(".one").click(function() {
$(this).removeClass("one").addClass("two");
console.log("one");
})
$(".two").click(function() {
console.log("two");
})
</script>
On the first click of one, the selector is no longer valid (as the class is now two instead of one). However the event is still bound to this element. This element will also not fire the ".two" handler as this has already been bound.
What would be the easiest way to unbind a handler with the initial click and then rebind afterwards?