I have a table
in a modal
, after clicking a button on this modal, the table is changed to another table.The first table is big so the modal width is large,while the second table is small, I want to change the width of modal in javascript after the second table appears, how can this be done?
$.ajax({
type:"POST",
url : 'UpdateResults.php',
data : {'Data':jsonString}
}).done(function(response) {
if (data == "Failed")
{
sweetAlert("","Error Occured!","error");
}
else
{
document.getElementById("UpDResults").style.display = 'block';
$("#UpDResults").append(response).trigger("update");
$("#Results").show();
$("#SearchResults").hide();
$("#UpdateResults").hide();
$("#NoData").hide();
document.getElementById('modal-3').style.width = '1080px';//Here what i tried
}
});
You can use class 'modal-dialog' and change the width. You can change the width in success function of Ajax call.
function ChangeWidth() { var d = document.getElementsByClassName('modal-dialog') for (var i = 0; i < d.length; i++) { d[i].style.width = "400px"; } }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open First Modal</button> <div> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <p>First Modal</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" onclick="ChangeWidth()">Change Wdith</button> </div> </div> </div> </div> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.