jQuery clone( true ) not working with dynamic elements
- by elclanrs
Take the following example:
$.fn.foo = function() {
var $input = $('<input type="text"/>');
var $button_one = $('<button>One</button>');
var $button_two = $('<button>Two</button>');
$button_one.click(function(){
$input.val('hey');
});
$button_two.click(function(){
$input.replaceWith( $input.val('').clone( true ) );
});
this.append($input, $button_one, $button_two);
};
Check the demo: http://jsbin.com/ezexah/1/edit
Now click "one" and you should see "hey" in the input. Next click "two" and then click "one" again and it doesn't work. Even using the true option in clone to copy all events it still does not work. Any ideas?