Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Bootstrap Modal hiding automatically


Removing element/s from BootStrap modal using ".remove", ".empty" or $("element").innerHTML = "", causes the modal to close automatically is there a fix?
to reproduce

<table class="table">
<thead>
<tr>
<th>Field Name</th>
<th>Field Type</th>
<th></th>
</tr>
</thead>
<tbody id="editFields">
<tr id="defaultRow">
<td>
<input type="text" class="form-control default" name="editNames[]" value="Amount" id="default" disabled>
<div class="text-muted fs-7">This is a default field and cannot be changed.</div>
</td>
<td>
<select name="editTypes[]" id="defaultSelect" class="form-select" disabled>
<option value="0" selected>Number</option>
</select>
</td>
<td></td>
</tr>
</tbody>
</table>


modal.find(".table").on("click", ".btn-danger", function() {
$(this).closest("tr").remove();
});


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi, Sean,

Thanks for the fast reply. It worked like a charm!



Glad to hear that happy All the best with your project.


Your Support Matters!

We will highly appreciate your Metronic Review on Themeforest.
Please go to Themeforest Downloads page, select Metronic & leave your feedback.

Hi,

The modal is closed due to the button click. Try to use Event stopPropagation


modal.find(".table").on("click", ".btn-danger", function(e) {
e.stopPropagation();
$(this).closest("tr").remove();
});


Regards.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(