javascript - Modal will not fade away after calling .modal('hide') -
first time working modal's , fade not working correctly, disappear upon cancelling, not disappear after confirming delete.
here modal w/ button
<span class="item-delete-button"> <button class="btn btn-danger col-lg-3 col-lg-offset-3" data-toggle="modal" data-target="#@item.id" onclick="deletestart(this)"> <span style="margin-right: 5px" class="glyphicon glyphicon-trash"></span>delete </button> </span> <!-- modal --> <div class="modal fade" id="@item.id" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="mymodallabel">delete</h4> </div> <div class="modal-body"> <span style="font-size: 20px">are sure want delete employee: @html.displayfor(modelitem => item.name)?</span> </div> <div class="modal-footer"> <button type="button" onclick="deletestopped(this)" class="btn btn-default" data-dismiss="modal">cancel</button> <button type="button" onclick="deletefunction(this)" class="btn btn-danger">confirm delete</button> </div> </div> </div> </div>
here jquery
function deletestart(element) { $(element).closest("table").toggleclass("table-hover"); $(element).closest("tr").css('background-color', 'red'); } function deletestopped(element) { $(element).closest("table").toggleclass("table-hover"); $(element).closest("tr").css('background-color', 'initial'); } function deletefunction(element) { var newid = $(element).closest("td").find("span.id").text(); $.post( '@url.action("customdelete", "employee")', { 'id': newid }, function (data) { }, "json" ); $(element).closest("tr").next("tr").remove(); $(element).closest("tr").remove(); $(element).closest("table").toggleclass("table-hover"); $(element).closest("tr").css('background-color', 'initial'); $('.modal').modal('hide'); }
any appreciated!
edit: tried adding $('.modal').modal('hide');
not seem helping, reference incorrectly?
issue found!
if try hide
modal within function temporarily leaves view (such ajax) must end modal's scripts before or else lost in application, , cannot hide
it.
to must call following within function before other functions/methods called such ajax post in situation.
this gets rid of fade
, hides
it.
$('#mymodal').removeclass('fade'); $('#mymodal').modal('hide');
Comments
Post a Comment