When you use .html(), the children will lose the events binded to it.
If you are copying just one element from one place to other than you can use .clone(true)
If you are moving multiple elements, like in your case, than you need to use element.contents()
For more details, read this.
Here is the Demo.
Changes to your code:
function change() {
if($.trim($(".div2").html()).length === 0 ) {
$(".div2").html($(".div1").contents());
$(".div1").html('');
}
else
{
$(".div1").html( $(".div2").contents() );
$(".div2").html('');
}
}