Reputation: 5117
How to do the next small thing:
<div id="mydiv">clickme</div>
If i click, "clickme" then appears "deleteme"
(function () {
$(document).ready(function () {
var initHtml = $('#mydiv').html();
$('#mydiv').click(function (e) {
$('#mydiv').html(initHtml + '<div>deleteme</div>');
});
$('#mydiv > div').click(function (e){
$('#mydiv').html(initHtml);
});
});
})(jQuery);
How to put to work the deleteme? If I click it, it doesn't disappear.
Upvotes: 0
Views: 17
Reputation: 11122
You will need to use event delegation with jquery on function since your division is dynamically created:
$(body).on('click','#mydiv > div',function (e){
$('#mydiv').html(initHtml);
});
Upvotes: 1