What is the process to close a modal that is currently open?

After copying a template from CodePen, I realized that the code was outdated and contained some old CDN links. This meant that I had to update these links in order to make the app fully functional. The last piece of the puzzle is figuring out how to close the modal after it has been opened. I suspect that the solution lies within Bootstrap. You can find the updated code for the links and the modal below.

<head>
        <title>Refugee Stories</title>
        <link rel = "stylesheet" href = "index.css">
        <meta name = "viewport" content="width = device-width,initial-scale=1.0">
        <meta charset="utf-8">
    <!-- jQuery Version 1.11.0 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
    integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
    </script> 
<!-- <link rel="stylesheet" href="index.css"> -->
<!-- Script -->

<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
    integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35455a454550471b5f4675041b">[email protected]</a>/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
    integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous">
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
    </head>
...
    <div class="portfolio-modal modal fade" id="portfolioModal5" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-content">
            <div class="close-modal" data-dismiss="modal">
                <div class="lr">
                    <div class="rl">
                    </div>
                </div>
            </div>
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 col-lg-offset-2">
                        <div class="modal-body">
                            <!-- Project Details Go Here..-->
                            <h2>Refugee Stories</h2>
                            <p class="item-intro text-muted">Html/Css/JavaScript</p>
                           <iframe width="560" height="315" src="https://www.youtube.com/embed/M4yl6ZXC3VY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                            <p>The Refugee Stories application allows users to read stories submitted by refugees. Admins have the ability to review, approve, or decline stories before they are published on the site. Users can submit their own stories for review as well. Both roles can view and read all stories available.</p>
                            <a href="https://refugeestoriesbw.netlify.app/"><button type="button" class="btn btn-primary"><i class="fa fa-times"></i> See Project</button>
                             </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Answer №1

UPDATE: According to @Atul's suggestion in his response, removing the duplicate jQuery include will ensure that the following code functions correctly.

$('#portfolioModal5').modal('hide');

.modal('hide')

This command manually hides a modal window.

For more information, refer to the bootstrap documentation here

Answer №2

In this demonstration, you will find an example of a working modal. I have noticed that jQuery is being called twice and the Modal Structure has not been implemented correctly according to the documentation, which is why it may not be functioning as expected

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://unpkg.com/popper.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css">
  <div class="row mb-4">
    <div class="col text-center">
      <a href="#" class="btn btn-lg btn-primary" data-toggle="modal" data-target="#portfolioModal5">Click to open Modal</a>
    </div>
  </div>


<!-- large modal -->
<div class="portfolio-modal modal" id="portfolioModal5" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-content">
            <div class="close-modal" data-dismiss="modal">
                <div class="lr">
                    <div class="rl">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">X</button>
                    </div>
                </div>
            </div>
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 col-lg-offset-2">
                        <div class="modal-body">
                            <!-- Project Details Go Here -->
                            <h2>Refugee Stories</h2>
                            <p class="item-intro text-muted">Html/Css/JavaScript</p>
                            <iframe width="560" height="315" src="https://www.youtube.com/embed/M4yl6ZXC3VY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                            <p>Refugee Stories is an application where you can read refugee stories once logged in. As a admin you can review stories  and either approve for the story to make it on the site or decline. As an  user you can submit stories for review. Both roles may view and read stories. </p>
                            <a href="https://refugeestoriesbw.netlify.app/"><button type="button" class="btn btn-primary"><i class="fa fa-times"></i> See Project</button>
                             </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic horizontal scrolling

I need help implementing a site using React that scrolls horizontally. I'm unsure how to implement certain aspects, so I am looking for some assistance. Within a wrapper, I have multiple container Divs. <div class="wrapper"> <div class=" ...

issues with getting bootstrap datetimepicker to function properly

I've been trying to integrate the bootstrap datetimepicker plugin into my web app by following all the installation instructions correctly. However, it doesn't seem to be working. I even tried some examples from others on jsfiddle that were refer ...

The error message "Error: 'x' is not a defined function or its output is not iterable"

While experimenting, I accidentally discovered that the following code snippet causes an error in V8 (Chrome, Node.js, etc): for (let val of Symbol()) { /*...*/ } TypeError: Symbol is not a function or its return value is not iterable I also found out ...

Adjust the position if the height exceeds 100 pixels

Can someone help with this code issue? $(document).ready(function () { if ($('.pi-img').height() > 100) { $(this).css('top' , '30%'); console.log('yeah'); } }); I am encountering difficu ...

Updating the value of a MongoDB item two days after its creation

I've been working on a NodeJS application that stores form data in a MongoDB database collection. My goal is to implement a function that can modify certain values of the object in the database collection 48 hours after the form data is initially save ...

Encountering a 500 (Internal Server Error) when attempting to post form-data using React JS on a Node server

POST https://waste-alert-api.herokuapp.com/datas 500 (Internal Server Error) In my latest project, I have developed a React application where users can upload an image along with some data. While most of the methods are functioning correctly, I am experie ...

What are some ways to enhance Javascript performance using Closure Compiler while preserving function names?

Seeking a solution for using specific functions from a Javascript file (lib.js) in a webpage without loading the entire file. I am looking to achieve this through command line scripting, but have not yet found a method that works as desired. The content ...

Having trouble updating the default value in a react-select field

I'm currently utilizing redux-form along with a custom component that integrates react-select. The dropdown I created allows for pre-filled options and the ability to input custom values. I am specifically using the "creatable" component from react-s ...

Exploring the contents of an array in ReactJS

const rowData = this.state.market.map((market) => { console.log("details", market["info"]) { return { marketInfo: ( <div> {market && !!market["info"] ? ( <div> ...

Is there a way to implement a jQuery plugin on the main page in Angular 2?

Is there a way to implement an image slider on a route page using Angular 2? I attempted to use flexslider and bootstrap carousel but was unsuccessful. Any tips on how to achieve this? The code for my Route Page: import { Component, ViewChild, ElementRef ...

Issue with jQuery.parseJSON causing empty data structure to return

I am facing a puzzling problem with manipulating data in JavaScript. The code snippet I am using in JavaScript is to fetch data from a PHP/MySQL source. var _response = jQuery.ajax({ url: "../data", async: false, type: "post", data: oPara ...

Navigate through a series of Selenium WebDriver elements while transitioning between pages

I am facing a bit of a challenge in constructing the logic for Selenium to navigate through a list of elements, like an unordered list, click on a link that takes it to another page, and then return to the original page to proceed with the next item in the ...

The data sent through the $.ajax POST request is being received as undefined in the server's response

My goal is to set up email functionality on my website. However, I am encountering an issue where the message returns as undefined when logged in the console. I am struggling to determine what information the server is receiving, as all attempts to log the ...

Transform my sidebar menu into buttons for mobile and smaller screens

As a newcomer to bootstrap, I've been experimenting with converting my sidebar into a button for smaller screen sizes. I've managed to customize everything to fit my needs except for one thing. When the screen size is reduced (as on mobile devic ...

Why is it not possible to declare an interface or type within a TypeScript class?

I am struggling to define interface | type within a TypeScript class. Here is the code snippet: class MyClass { interface IClass { name: string, id: string } } However, I keep encountering this error: Unexpected token. A constructo ...

What is the best way to retrieve tags from an HTML document and transfer them to a different file?

My webpage structure is as follows <unit id="2" status="FINISHED" type="pe"> <S producer="Alice_EN">CHAPTER I Down the Rabbit-Hole</S> <MT producer="ALICE_GG">CAPÍTULO I A ...

Customizing App (directory) elements in next.js 13

Imagine having this directory organization: https://i.stack.imgur.com/Hd5gu.png Is there a method for loading the component from the custom folder instead of the default one in the app folder? In case the custom folder does not have that component, can t ...

In IE7, when a parent element has a child element that is positioned relatively, the

I've configured a navigation bar with an unordered list of links, and added a 10px border to each list item. Due to the font I am using having excess space above each character, I have applied position: relative to the links and moved them up by 6 pi ...

Steps for adding a navbar that slides horizontally and overlaps other links on a webpage

I am attempting to design a sliding navigation menu using JQuery. The concept involves having multiple main sections, each with several subsections. When a user hovers over a section, the subsections will expand horizontally. If another section is current ...

Does JavaScript have an event handler called "onPageRendered"?

I am currently working on a JavaScript program that should start running when my HTML page is loaded. However, I am facing an issue where the initial message does not appear as expected on the page. Upon reviewing the code, I noticed that all the DOM updat ...