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

Conceal the div element five seconds after the registration process is completed

Is it possible to automatically hide a div 5 seconds after a user registers? Using the timestamp in PHP for the user's registration, there may be a way to achieve this with jQuery, but it's not certain. I found a script online that successfully ...

Incorporating an image prior to the "contains" term with the help of JavaScript

Seeking assistance with the code snippet below without altering the text targeted in my "a:contains" statement. The challenge lies in determining the appropriate placement of ::before in the script provided. Link: https://jsfiddle.net/onw7aqem/ ...

How can you use jQuery to transform a H3 tag into a clickable link?

To transform the h3 tag into a clickable link with jQuery and set the href attribute, while preserving the H3 styling and adding an anchor tag, you can use the following code as an example: Click Here ...

Updates in .net modify values prior to the file being downloaded as a Word document

After dynamically filling my page values with jQuery, I am trying to generate a Word file. However, when the Word file is created, it does not reflect the new values brought in by jQuery. Here is the ASPX code: <form runat="server"> <asp:Label r ...

"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= ...

Prevent form submission from refreshing the page by using jQuery and ajax

I'm looking to submit a form without refreshing the page, but my current script isn't working as expected: $('#formId').submit(function(e){ $.ajax({ type: "POST", url: 'serverSide.php', data: $(&ap ...

Unable to retrieve input value from dynamically-generated field with JQuery

There seems to be an issue with receiving a value from a static field when using the keyup method based on the input field class (.inputclass). Once a field is added dynamically, it does not get the value. Below is a sample code. Any help would be appreci ...

What is the best strategy for queuing AJAX requests when they depend on input from previous requests for efficiency?

I am currently developing an application within the SharePoint platform that requires making three distinct AJAX requests: Firstly, a call to the Search API is made to retrieve all individuals with a specific job title associated with the account ID (sea ...

Loading JS and CSS files in relation to the website root directory

When it comes to including CSS/JS files, what are the best practices for defining the file URI? Some people prefer to include files relative to the website root by specifying the full URI: <link rel="stylesheet" href="/my/path/to/css/main.css"> Thi ...

Is there a method to ensure that the window event always gets triggered before any other events?

Is there a way to make the window event trigger first when clicking on #myDiv? (function ($, w, d) { $(d).ready(function () { $(w).click(function() { alert('window has been clicked'); }); $('#myDiv').cl ...

An element in CSS that has a position of fixed and a width of 100% surpasses the dimensions of its

My element has the CSS properties position:fixed and width:100%, causing it to be larger than its parent elements. Despite the complexity of my code, I have attempted to simplify it for better understanding. Below, you can see that the green box exceeds ...

Refreshing the <select> value following changes to <option> tags

I've included my code snippet below. The goal is to update the options of a select box and then reset its value back to what it was before the change. Unfortunately, this approach is not achieving the desired result. Any insights on what might be caus ...

What is the best way to dynamically assign a value to an anchor tag upon each click using jQuery?

How can I pass a value to an anchor tag on every click using jQuery? I am encountering an issue with my current code where the value is not being retrieved when I click the button. //HTML snippet <button id="a-selectNm" data-a_name="<?php echo $row[ ...

Unable to connect to a style sheet

I'm in the process of developing a web application and I'm facing an issue with linking a stylesheet to my app. Check out my code below: <html> <head> <title>Bubble</title> </head> <link rel=" ...

The PHP-MySQL connection is successful, but the link is being rearranged within the table

I am currently working on implementing an Ajax call to update a portion of a webpage when a user clicks on a link within a table. The data is successfully retrieved, but the issue arises when the user has scrolled down to access the link - each time the da ...

Can you explain the contrast between "#msg" and "#msg div" when used in a style tag?

<html> <head> <style> #msg { visibility: hidden; position: absolute; left: 0px; top: 0px; width:100%; height:100%; text-align:center; ...

Attempting to change the text of a Bootstrap button using jQuery when clicked

Looking to create a mobile navigation menu that toggles between displaying "Menu" and "X" when clicked. Check out the code on jsfiddle $(document).ready(function() { $('.navbar-toggle').on('click', function () { if (matchMe ...

Tips for ensuring an element stays anchored at the bottom even when the keyboard is displayed

I recently encountered a situation on one of my pages where an element positioned at the bottom using absolute positioning was causing issues when the keyboard was opened, as it would move to the middle of the page unexpectedly. While this may seem like a ...

The customized styling for Material Angular does not seem to properly apply to <md-card> elements within ui-views

I am trying to achieve a specific effect on the ui-views <md-card id="sidebar" flex="20" class="sche-card" layout-padding="true"> <div ui-view="card" autoscroll="false"></div> </md-card> However, I am facing an issue where the car ...

The functionality of the Wordpress editor is impaired when the parent element is set to display:none during rendering

My goal is to create a popup window with text fields and a wp_editor. The content is already rendered in the footer but only set to display none. I have made attempts at implementing this, however, they are not working perfectly. Each approach has its own ...