Guide to Creating a Pop Up Image Display with Bootstrap

Can someone help me achieve the same functionality as the Fiddle linked below?

http://jsfiddle.net/6CR2H/1/

I have tried to replicate it by including both external files, but the image is not displaying as a pop-up when clicked.

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">

<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<a href="#" class="pop">
    <img src="http://patyshibuya.com.br/wp-content/uploads/2014/04/04.jpg" style="width: 400px; height: 264px;">
</a>

<a href="#" class="pop">
    <img src="http://upload.wikimedia.org/wikipedia/commons/2/22/Turkish_Van_Cat.jpg" style="width: 400px; height: 264px;">
</a>

<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">              
      <div class="modal-body">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <img src="" class="imagepreview" style="width: 100%;" >
      </div>
    </div>
  </div>
</div>

<script>
$(function() {
        $('.pop').on('click', function() {
            $('.imagepreview').attr('src', $(this).find('img').attr('src'));
            $('#imagemodal').modal('show');   
        });     
});
</script>

If anyone can assist me in identifying why the images are not popping up, I would greatly appreciate it.

Thank you!

Answer №1

Bootstrap relies on jQuery for its functionality.

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<a href="#" class="pop">
  <img src="http://patyshibuya.com.br/wp-content/uploads/2014/04/04.jpg" style="width: 400px; height: 264px;">
</a>

<a href="#" class="pop">
  <img src="http://upload.wikimedia.org/wikipedia/commons/2/22/Turkish_Van_Cat.jpg" style="width: 400px; height: 264px;">
</a>

<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <img src="" class="imagepreview" style="width: 100%;">
      </div>
    </div>
  </div>
</div>

<script>
  $(function() {
          $('.pop').on('click', function() {
              $('.imagepreview').attr('src', $(this).find('img').attr('src'));
              $('#imagemodal').modal('show');   
          });     
  });
</script>

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

jQuery AJAX not properly delivering data to PHP server

For a while now, I've been struggling with a persistent issue. Despite trying numerous solutions, I still can't seem to get it to work properly. Even the simplest example like this doesn't seem to be functioning correctly in my case: jQuer ...

Update a variable in one component class using another component

My Hue class in a component contains a variable that I'm trying to modify: export default class Hue extends Component { state = { toggleState : false, toggleWhite : false } render(){...} ... } Within this component, I can chang ...

What is the best way to use a regex to filter the user's input in a Vuetify combobox and generate a chip?

I am working on implementing a restriction for a specific regex pattern while the user types in a combobox to add new chips, such as allowing only phone number chips. Complete Vue Source code: https://codesandbox.io/s/chips-so-0gp7g?file=/src/domains/ex ...

Exploring the versatility of Bootstrap and JQuery's draggable feature

I am currently working on a website that will enable users to search through a list of courses. Once a course is chosen from a typeahead search, it will be added to a basket. Users can then drag and drop the selected courses into one of four semesters disp ...

I need help with making multiple XMLHttpRequests within a single JavaScript file. Can someone provide guidance on

https://i.sstatic.net/M0EJk.png Hey lovely people! I need some help. I'm trying to send two HTTP GET requests and log their responses in the console. However, I'm only seeing the response from the first request and the second one seems to be stuc ...

Pressing enter to submit a form when the submit button is not visible is functional in Firefox, but has no effect in Chrome

There is a form with various input fields and a hidden submit button (hidden using style="display:none"). Interestingly, in Firefox, pressing the return key while an input field is focused automatically submits the form. However, in Chrome, hitting retur ...

What is the best method to assign a property to a model within AngularJS by utilizing an attribute parameter?

I am in the process of creating a custom directive in AngularJS for a UI slider that can be used multiple times. Each slider should be able to bind to a specific property. My idea was to use an attribute called "property" which would automatically update w ...

Encountered problem with AJAX in Java: Unable to assign value to property 'innerHTML' as it is null

Recently, I've been eager to dive into learning AJAX and decided to create an app following a tutorial similar to the one provided here. However, after painstakingly replicating the code, I found that it's not working as expected. Despite multipl ...

Storing user input and form data dynamically through JSON

Hi there, I'm a newcomer to the world of JSON and I know this question has likely been posed before, but I just want to double-check that I'm on the right track. I'm in need of creating a dynamic form for various pages. I want the flexibili ...

Tips for adjusting column sizes in ag-grid

I'm a beginner with ag-grid and need some help. In the screenshot provided, I have 4 columns initially. However, once I remove column 3 (test3), there is empty space on the right indicating that a column is missing. How can I make sure that when a col ...

mentioning someone using the @ symbol

I am currently in the process of creating a tagging system for users. I have almost completed it, but there is one issue that I cannot seem to figure out. I know what the problem is, but I am struggling to come up with a solution. When I input the @ sign ...

Is it possible for Response.Redirect and OnBeforeUnload to cooperate effectively?

Is there a way to detect if the server-side code has sent a Response.Redirect in an OnBeforeUnload event? I need to alert the user before they navigate away from a page, but I don't want the prompt to appear when the server redirects. I'm dealin ...

What could be causing my Ajax success function to never fire?

My issue is that my $.ajax success function is not triggering. I simply need to execute a PHP file without passing or retrieving any values. I found an alternative method for reading values, but it cannot run because the function must be placed within th ...

Is there a way to eliminate the "Use different Apple ID" option when setting up Sign in with Apple on a Reactjs + React Native App?

Currently working on integrating Sign in with Apple into my React Native + Reactjs frontend stack. The challenge I am facing is wanting to eliminate the "Use a different Apple ID" option, similar to how Binance has achieved it in their implementation (fir ...

Mobile devices do not support HTML5 Video playback

Here is the HTML5 Video code I am using: <div id="lightBox1" class="lightBox"> <video id="video" controls preload="metadata"> <source width="100%" height="470" src="/ImageworkzAsia/video/iworkzvid.mp4" type="video/mp4"> ...

Tips for resizing images without using media queries in CSS

I have a name plate image labeled (PAST CHAMPIONS) for the plaque, and it appears fine on most screens except for iPhone portrait mode, where it gets cut off. Is there a way to make this image scale without using media CSS? Here is the link to the homepa ...

Personalizing the message displayed by the PHP exit function

My goal is to enhance the appearance of the message page produced by the PHP exit function for a better user experience. At the moment, all that is visible is a blank, white screen. Is there a way to customize this page to include a personalized message, ...

What steps can be taken to resolve the vulnerability in webpack-pwa-manifest?

Looking for solutions to address the [email protected] and minimist vulnerability. I attempted removing node/modules and package-lock.json, followed by a fresh npm installation, but the issue persists. Any suggestions would be greatly appreciated. Scr ...

What are some ways to customize the appearance of the Material UI table header?

How can I customize the appearance of Material's UI table header? Perhaps by adding classes using useStyle. <TableHead > <TableRow > <TableCell hover>Dessert (100g serving)</TableCell> ...

substitute the character ""<0x00>"" within the given string

I'm currently facing an issue with a string I received after sending a command line that included the <0x00> character. How can I remove it from the string? For instance, here is my variable string: <0x00> awplus # desired output: awplus ...