What adjustments must be made to the Bootstrap 5 example below in order to achieve the following two objectives:
- The "afterAcceptingTerms" division should remain hidden until the user clicks on the Accept Terms modal button, ensuring that only the "beforeAcceptingTerms" division is visible prior to this action.
- Upon clicking on the Accept Terms modal button, the "afterAcceptingTerms" division should become visible while the "beforeAcceptingTerms" division is concealed.
While the following code snippet represents our initial Bootstrap 5 setup, it does not successfully implement the required toggling of div classes as outlined above.
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Modal Popup Page</title>
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
<script src="/assets/js/popper.min.js"></script>
<script src="/assets/js/bootstrap.min.js" ></script>
</head>
<body>
<div class="wrapper" id="beforeAcceptingTerms">
<section class="content-section">
<p>To access the content of this page, you need to click on the "I agree to the terms" button.</p>
</section>
</div>
<div class="wrapper" id="afterAcceptingTerms">
<section class="content-section">
<p>Page content will be displayed here after accepting the terms by clicking the modal's Accept button and closing the modal.</p>
</section>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="exampleModalLabel" data-bs-backdrop="static" aria-hidden="true">
<div class="modal-dialog" style="position: fixed;bottom: 0;left: 0;right: 0;">
<div class="modal-content">
<div class="modal-body">
By using this site, you certify that you agree to our <a href="/terms">Terms of Use</a>.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="localStorage.setItem('acceptTerms',1)">I agree to the Terms.</button>
</div>
</div>
</div>
</div>
<script>
let acceptTerms = localStorage.getItem('acceptTerms');
if(acceptTerms != 1){
var myModal = new bootstrap.Modal(document.getElementById('myModal'), {})
myModal.show()
}
</script>
</body>
</html>