Expanding image in table data to full screen upon clicking using jQuery

I am trying to display an image in my table and then use jQuery to pop up a modal with the full-screen image. However, the image only pops up at the top of the table data.

This is the code I have so far:

<tbody>
  <tr>
    <td><?php echo $i++;?></td>
    <td><?php echo $d['tanggal_komplain'];?></td>
    <td><?php echo $d['nama_komplainer'];?><?php echo $d['pembuat'];?></td>
    <td><?php echo $d['departemen_tujuan'];?></td>
    <td><?php echo $d['personil_tujuan'];?></td>
    <td><?php echo $d['subject'];?></td>
    <td><?php echo $d['isi_komplain'];?></td>
    <td><?php echo $d['status'];?></td>
    <td class="align-middle text-center perbesar">
      <a href="#" id="pop">
        <img id="imageresource" src="image/<?php echo $d['nama_gambar']; ?>" width="80" height="80">
      </a>
    </td>
  </tr>
</tbody>    
<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-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Image preview</h4>
      </div>
      <div class="modal-body">
        <img src="" id="imagepreview" style="width: 400px; height: 264px;" >
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<script>
$("#pop").on("click", function() {
   $('#imagepreview').attr('src', $('#imageresource').attr('src')); // here assign the image to the modal when the user clicks the enlarge link
   $('#imagemodal').modal('show'); // imagemodal is the id attribute assigned to the bootstrap modal, then I use the show function
});
</script>

I'm hoping someone can offer some assistance with this issue :((

Answer №1

Implement the use of preventDefault to effectively disable a link

`$("#pop").on("click", function(e) {
     e.preventDefault();
 $('#imagepreview').attr('src', $('#imageresource').attr('src')); // This line assigns the image to the modal when the user clicks the enlarge link
 $('#imagemodal').modal('show'); // Here, imagemodal is the id attribute assigned to the bootstrap modal, then the show function is used
 });`

(or)

To disable the link, remove the href and add type=button in the pop link...

<a type="button" id="pop">...</a>

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

Confirm that the input into the text box consists of three-digit numbers separated by commas

Customers keep entering 5 digit zip codes instead of 3 digit area codes in the telephone area code textbox on my registration form. I need a jQuery or JavaScript function to validate that the entry is in ###,###,###,### format without any limit. Any sugge ...

Update the form action URL when a specific option is selected from the dropdown menu upon clicking the submit

I would like my form to redirect to a specific page on my website based on the selection made in the <select> tag. For instance, if '2checkout' is selected, it should go to gateways/2checkout/2checkout.php. Similarly, if 'Payza' i ...

Using jQuery to load HTML response into entire page

When working with my ajax code, I receive a html response. Is there a way to entirely replace the current page with this html response? So far, I have only come across window.location.href, which simply redirects to the url response. Here is a snippet of ...

SB Admin 2 menu with multiple levels does not collapse as expected

I'm in the process of integrating the menu from the sb admin 2 template into my Ruby on Rails application: As I gradually added components to test functionality, I successfully implemented the top and side nav bars. However, I encountered an issue wi ...

If I utilize npm in Visual Studio Code, where can I find the installation location of my

After installing jquery for use, I'm having trouble locating where it's been installed. Where is my jquery file stored and how can I locate it? ...

Techniques for Adding Background Color to Fieldset Border

Recently starting to learn HTML and stumbled upon a question: How can I create a background color or image for a field set border? Can I simply use regular color values, or do I need special codes for creating a background color in a field set? Any insig ...

Issue with toggling div visibility

Is it possible to use JQuery to toggle visibility of a specific div with the id "d_1" when a button with the id "i_1" is clicked, causing it to slide right while appearing? ...

Use jQuery to redirect the user if the URL does not match

Is there a way to automatically redirect users to a specific page if they are not currently on that page? For example, something like the following pseudo code: if not (url = example.com/index.php) redirect to example.com/index.php /if When a user vi ...

Issues persisting with vertical alignment in table cells on Firefox browser

I've successfully managed to vertically center the contents of .onesizechart in Chrome and Safari, but I'm facing issues with Firefox and IE. Interestingly, the contents of .homepage-sizechart are displaying correctly, leading me to believe that ...

Why is it that the default theme of Material UI lacks any stylization at all?

After experimenting with both Carbon Design for React (@carbon/react) and Material UI (@mui/material) in conjunction with Next.js, I encountered styling issues with the components. While they functioned correctly to some extent, there were noticeable discr ...

No data being returned by $.get in Internet Explorer

I'm currently utilizing JQuery's $.get method to retrieve a twitter feed and showcase it on my website. Strangely, I am encountering an issue where no data seems to be fetched (i.e., the code within function(d) { ... } is not being executed). Thi ...

Troubleshooting Div Element Width in CSS Not Functioning

When working on a form design, I encountered an issue where the text labels were not aligning to the same width. Despite setting the width, it didn't seem to work as expected: .form-label { display:inline; width: 160px; } <div class="form-label ...

Using JQuery to reveal a hidden child element within a parent element

I'm facing a challenge with displaying nested ul lists on my website. The parent ul is hidden with CSS, causing the child ul to also remain hidden even when I try to display it using jQuery. One approach I've attempted is adding a class to the f ...

Exploring a React JS option for filtering repeated elements, as an alternative to Angular

While using Angular JS, I came across the 'filter' option within ng-repeat which is useful for live search. Here's an example: <div ng-repeat="std in stdData | filter:search"> <!-- Std Items go here. --> </div> &l ...

Tips for generating an HTML template as a string using jQuery

I have developed a dynamic modal using plain JavaScript, triggered by a button click. This modal is controlled based on the attributes `data-open-hours` and `data-closed-hours` in the HTML. If you take a look at my demo, you will notice an issue. Let me e ...

Attempting to create a fixed div at a specific position, however, an unexpected Uncaught TypeError disrupted additional code functionality

Is there a way to make a div stay fixed in place while scrolling, but then unstick at a specific point? I found some code that seemed to work for this purpose, but unfortunately it caused an error that affected other jQuery scripts. The console displayed t ...

The exact problem with aligning the table

Below is a simplified version of my code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body style="font-size: 36px"> </body> </html> <html> ...

Arrangement featuring two distinct types of tiles

Looking for a way to achieve this layout using just CSS or a combination of CSS and a little JS. Click on my avatar to see the reference image enlarged =) I've tried using floats and display options but haven't been successful. Take a look at htt ...

Can a JavaScript framework be created to ensure all browsers adhere to standards?

As someone who isn't an expert in JavaScript, I wonder if it's feasible to create a comprehensive embeddable JavaScript file that ensures all browsers adhere to standards. Could there be a compilation of known JavaScript hacks that compel each br ...

producing base64 encoding that results in a blank image

I have some code that is supposed to get an image from a video using canvas. However, when I save this base64 code into an image, I end up with a black image. What could be causing this issue? Here is my JavaScript code: var input = document.getElementBy ...