Reputation: 3021
I am trying to append
body of the bootstrap modal dynamically. Here is the body Markup of the Modal.
<!-- try to indent the codes for readability -->
<div class="modal-body">
<div class="row text-left" style="margin-left: 2em;">
<div class="form-group"></div>
</div>
</div>
and here is the Jquery code to append the contents on click event of a button.
$('.form-group').append(EditHTML);
EditHTML
is the markup that got generated dynamically. Now issue is that with every button click event EditHTML
is being added with the previous content. I need to reset the Modal, each time button is click.Please help.
Upvotes: 0
Views: 170
Reputation: 114
I'm not sure I have understood right:
$('.form-group').html(EditHTML);
Upvotes: 0
Reputation: 5622
Just use .html()
$('.form-group').html(EditHTML);
Description : When
.html()
is used to set an element's content, any content that was in that element is completely replaced by the new content. Additionally, jQuery removes other constructs such as data and event handlers from child elements before replacing those elements with the new content.
Upvotes: 2