The modal created with Bootstrap 4 is not appearing on the local server, using code sourced from codepen.io

I recently experimented with modal using Bootstrap 4 from a code I found on this website

    <div class="container">
    <h1>Experience Playing YouTube or Vimeo Videos in Bootstrap 4 Modal</h1>


 <!-- Button trigger modal -->
<button type="button" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/Jfrjeg26Cwk" data-target="#myModal">
  Play Video 1
</button>

   <!-- Button trigger modal -->
<button type="button" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/IP7uGKgJL8U" data-target="#myModal">
  Play Video 2
</button>


   <!-- Button trigger modal -->
<button type="button" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/A-twOC3W558" data-target="#myModal">
  Play Video 3
</button>


     <!-- Button trigger modal -->
<button type="button" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://player.vimeo.com/video/58385453?badge=0" data-target="#myModal">
  Play Vimeo Video
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">


      <div class="modal-body">

       <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>        
        <!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item" src="" id="video"  allowscriptaccess="always">></iframe>
</div>


      </div>

    </div>
  </div>
</div> 



</div>

CSS styles :

body {margin:2rem;}

.modal-dialog {
      max-width: 800px;
      margin: 30px auto;
  }



.modal-body {
  position:relative;
  padding:0px;
}
.close {
  position:absolute;
  right:-30px;
  top:0;
  z-index:999;
  font-size:2rem;
  font-weight: normal;
  color:#fff;
  opacity:1;
}

Javascript functionality :

$(document).ready(function() {

// Retrieves the video source from the data-src attribute of each button
var $videoSrc;  
$('.video-btn').click(function() {
    $videoSrc = $(this).data( "src" );
});
console.log($videoSRC);



// Autoplay the video when modal is opened  
$('#myModal').on('shown.bs.modal', function (e) {

// Set the video source to autoplay and hide related videos. Prevent annoying surprises!
$("#video").attr('src',$videoSrc + "?rel=0&amp;showinfo=0&amp;modestbranding=1&amp;autoplay=1" ); 
})


// Stop playing the Youtube video when modal is closed
$('#myModal').on('hide.bs.modal', function (e) {
    // Simple way to stop the video
    $("#video").attr('src',$videoSrc); 
}) 






// Document ready function    
});

The modal does not appear when tested on localhost. Can anyone suggest a solution for this issue? Your help would be greatly appreciated.

Note: The code has been edited slightly.

Below are the links to the CSS and Javascript files used locally:

Answer №1

To utilize Bootstrap 4, Popper.js is a necessary dependency. Therefore, failing to include it will prevent you from using Bootstrap 4. Visit this link to access Popper.js

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

Utilizing a particular Google font site-wide in a Next.js project, restricted to only the default route

My goal is to implement the 'Roboto' font globally in my Next.js project. Below is my main layout file where I attempted to do so following the documentation provided. import type { Metadata } from "next"; import { Roboto } from "n ...

"Oops! Looks like there's a reference error - the function you're trying

Javascript: function insertSmiley(a) { var $img = $(a).children('img'); $("#message").insertAtCursor(($("#message").data("wbb").options.bbmode) ? $("#message").data("wbb").toBB($(a)): $(a).html()); return false; } HTML: <a href= ...

Encountering the NullInjectorError when Angular 17 is unable to find a provider for the function(options)

I'm new to Angular (version 17) and encountered an error: ERROR Error [NullInjectorError]: R3InjectorError(Standalone[_LoginPageComponent])[function(options) { -> function(options) { -> function(options) { -> function(options) { -> functio ...

Comprehending the process of sending a variable to Routes within Node.js

Hey there! I have a MongoDB functions file where I need to pass a value generated by a function to the routes file, but I'm having trouble figuring out how to do that. The file is called labels.js const findLabels = function(db, callback) { // Acc ...

Ember.js: My fixtures array is getting cleared out based on the way it is being accessed

I have 2 different controllers in my application. The first one, KeywordsIndexController, is defined as follows: App.KeywordsIndexController = Em.ArrayController.extend({ contentBinding: "App.Keyword.FIXTURES" }); The second controller, KeywordsNew ...

Establishing the redux provider in conjunction with react admin

Looking to implement a redux store in my project without using it in react admin, just in the rest of my application. I have included the usual redux provider code in my src/index.js file: ReactDOM.render( <Provider store={store}> <Ro ...

By clicking the button, you can add an item to select2

Utilizing the select2 tag style in my Drupal YAML form allows users to easily locate and add various items. These items come with both images and titles on the same page, accompanied by a button next to each image. My goal is to enable users to click the b ...

Eliminate the tag while retaining the contents using jQuery or Javascript

Feeling a bit tired tonight and struggling to figure out this task. I have a similar problem like the one below where I need to remove HTML tags but keep their contents: <a href="#">some content</a> and more <a href="#"> and more content ...

Alerting error message during Laravel array validation via ajax causes error to be thrown

Seeking assistance with validating arrays in Laravel using FormRequest validation <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class VendorStoreRoom extends FormRequest { /** * Dete ...

What is the method for socket.emit() data that originates from a function?

Using Socket.io with Node.js Sending data from the server to the client is straightforward when using a string or hard-coded variable: var greeting = 'hello'; socket.emit('greeting', greeting); However, things get tricky when trying ...

The onClick function is failing to work properly, and I need to pass the value of 'cid' based on the result of the button

Is it possible to pass the 'courseid' to local storage when a button is clicked? I am having trouble with onclick not working. How can I retrieve the relevant 'courseid' in the onclick function based on the button clicked? handleClick ...

The feature of determining if an edge exists, within the dagre-d3/graphlib,

Has anyone utilized the graph.hasEdge function in dagre-d3/graphlib to check for the existence of an edge between two nodes? This API takes two arguments representing the two nodes and verifies if there is an edge connecting them. I am facing an issue whe ...

Removing spaces in the Datatables pagination buttons: A step-by-step guide

Seeking assistance in removing spaces in the pagination buttons of datatables. Can you please help me achieve this? https://i.sstatic.net/JwQQw.png I have tried following the instructions from the URLs below: DATA TABLES BOOTSTRAP 4 EXAMPLE Despite add ...

The limitations of modifying a scope within an ng-if statement versus using a function call in AngularJS

Here are the code snippets demonstrating the toggling of the hideQA value. The value changes correctly in both conditions, but the divs are not hiding properly when using - `<button ng-click="hideQA = !hideQA">Reset</button>` However, if I ch ...

Obtaining Browser Console Logs with Python Selenium - TCF API Integration

I am looking to extract Tracking Consent Strings (TC-strings) from websites that have implemented the Tracking Consent Framework for GDPR compliance. In the browser console, I can use the following code snippet: window.__tcfapi('ping', 2, functio ...

"Encountering issues with CSRF token validation in an Angular SpringBoot application when making an Ajax POST request, resulting in an

Current Project Details The ongoing project involves developing a single-page Angular JS application using SpringBoot with a Spring Security implementation. The application, known as 'Study Planner', allows students to input their study leave on ...

Sorting the table: the parser for the table.config[c] is not defined

I've been struggling with the tablesorter plugin, as it doesn't seem to be functioning properly in sorting the table. Can someone please assist me? I've been trying to solve this issue for two days now. Here is the error: table.config.pars ...

Dropzone failing to verify the maximum file limit

I am currently using dropzone to upload files on my website. I have limited the number of files that can be uploaded to a maximum of six. The code works perfectly when uploading one image at a time, but if I select more than six images by holding down the ...

What steps can be followed to create functionality for having three pop-up boxes appear from just one?

I have implemented code that triggers pop-up boxes at the bottom of the screen when a user clicks on a name from a list displayed on the top right corner of the screen. <!doctype html> <html> <head> <title>Facebook Style Popu ...

How should one go about organizing the JavaScript code for a complex application?

Imagine you are working on a complex project with extensive use of JavaScript throughout the site. Even if you divide the JavaScript into one file per page, there could still be around 100 JavaScript files in total. What strategies can you implement to ma ...