Adjusting the image placement within a modal window (using bootstrap 3)

Behold, an example modal:

    <!-- Large Modal -->
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">funnycatnumberone</h4>
      </div>
      <div class="modal-body">

    <div class="row">
       <div class="col-lg-8 col-md-8">
        <img src="cat1.JPG" class="img-responsive">
       </div>
       <div class="col-lg-4 col-md-4">
           <p>brief description about my cat</p>
           <ul class="list-unstyled">
               <li>it has four legs</li>
               <li>also a tail</li>
               <li>likes boxes</li>
           </ul>
       </div>
       <br>
    </div> 
    <br>
    <div class="row">
        <div class="col-sm-2">
            <img src="cat2.JPG" class="img-responsive">
        </div>
        <div class="col-sm-2">
            <img src="cat3.JPG" class="img-responsive">
        </div>
        <div class="col-sm-2">
            <img src="cat4.JPG" class="img-responsive">
        </div>
        <div class="col-sm-2">
            <img src="cat5.JPG" class="img-responsive">
        </div>     
    </div>
</div>
      <div class="modal-footer">
        <a type="button" class="btn whateverclassimade" href="cutecatsmkay.php">check out some cats, yo</a>
        <a type="button" class="btn whateverclassimade" data-dismiss="modal">Close</a>
      </div>
    </div>
  </div>
</div>

Once the modal is open, you'll find a title, a large image (positioned on the left below the title), a short description with additional details, four thumbnail images directly beneath the main picture, and buttons for closing the modal or navigating to another page.

My query is this: How can I make it so that when a user clicks on a thumbnail (below the main image), that thumbnail then replaces the larger image (essentially becoming the main focus)? Any assistance would be greatly appreciated!

Answer №1

experiment with this:

$("#preview img").on("click", function(){ 
$("#full_image").attr("src", "picture source"); 
});
make sure to match ids with their respective elements

Answer №2

Here is a straightforward example in pure JavaScript:

function changeImage(catID) {
  document.getElementById("largeCat").src = document.getElementById(catID).src;
};
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">cutekittynumberone</h4>
      </div>
      <div class="modal-body">

        <div class="row">
          <div class="col-lg-8 col-md-8">
            <img id="largeCat" src="http://placekitten.com/g/500/600" class="img-responsive">
          </div>
          <div class="col-lg-4 col-md-4">
            <p>short description of my adorable kitten</p>
            <ul class="list-unstyled">
              <li>it has whiskers</li>
              <li>a fluffy tail</li>
              <li>loves chasing yarn</li>
            </ul>
          </div>
          <br>
        </div>
        <br>
        <div class="row">
          <div class="col-sm-2" onclick="changeImage('smallKitten1');">
            <img id="smallKitten1" src="http://placekitten.com/g/500/300" class="img-responsive">
          </div>
          <div class="col-sm-2" onclick="changeImage('smallKitten2');">
            <img id="smallKitten2" src="http://placekitten.com/g/500/400" class="img-responsive">
          </div>
          <div class="col-sm-2" onclick="changeImage('smallKitten3');">
            <img id="smallKitten3" src="http://placekitten.com/g/500/500" class="img-responsive">
          </div>
          <div class="col-sm-2" onclick="changeImage('smallKitten4');">
            <img id="smallKitten4" src="http://placekitten.com/g/500/600" class="img-responsive">
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <a type="button" class="btn cute-cat-link" href="cutecats.html">view more cute cats</a>
        <a type="button" class="btn close-modal" data-dismiss="modal">Close</a>
      </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

Sending out a command does not equate to establishing Redux with an outcome

I've been grappling with this issue for the past 18 hours and I'm at a loss to figure out what's causing the problem. My redux setup is working smoothly as it dispatches actions and receives state correctly for other components. However, in ...

"Crafting sleek and polished titles using HTML and CSS - A step-by-step guide

I've noticed an increasing number of websites that feature incredibly slick headlines, such as the ones on this site: How do these websites achieve this effect? Are there any subtle hints to look out for? I once heard about a technique involving Fla ...

Is there a way to ensure that an external file function completes before proceeding with the main code execution?

In my project, I have two key JavaScript files: main.js and load.js. Within load.js, there are two essential functions - getData, which makes an AJAX post call, and constHTML, which appends data based on the JSON array returned from the AJAX call. This app ...

JavaScript Await Dynamic User Input

I have implemented a modified version of a script for generating random numbers in multiple columns of a spreadsheet, inspired by Tim Cooper's solution on stackoverflow. This script works by selecting a range of cells and running it from an onOpen men ...

The inefficacy of the JQUERY validation plugin, AJAX, and PHP integration

After diving into learning AJAX for submitting forms, I've encountered a roadblock. The data I submit doesn't seem to reach the PHP file as expected, and I can't figure out why it's failing. Here's my HTML: <div class="col-md- ...

What is the best way to activate a click event within an ng-repeat loop in AngularJS

Is there a way to trigger an event click handler in angular where clicking the button will also trigger the span element? I've tried using the nth-child selector without success. Any suggestions on how to achieve this? I also attempted to use jQuery s ...

Is it possible to dynamically assign and call functions through an Object in Angular 6?

I implemented a click handler for a button that is generated dynamically. Within the click handler function, I am invoking a callback function. However, I encountered an issue where an error message popped up stating that "Callback function is not a fu ...

The content of the served HTML Table remains static and requires a server restart for any updates to

Having been encountering this issue for quite some time, I have searched extensively for a solution but to no avail. Therefore, I am taking matters into my own hands and posing the question myself. The dilemma is as follows: https://i.stack.imgur.com/UZrQ ...

What is the best way to filter through JSON data in Vue.js?

I'm encountering an issue with my JSON file that I am rendering to a table. I have 11 columns including id, name, and more. I want to search by every column, but the functionality only works for one column. If I try to filter the data multiple times, ...

Is there a difference between new Date(..).getTime() and moment(..).valueOf() in momentJS?

new Date(..).getTime() is expected to provide a timestamp in milliseconds. In the documentation of momentJS, it states that the expression moment(..).valueOf() should also yield a timestamp in milliseconds for a given date. To verify this claim, I conduct ...

Modifying td background color according to values in a PHP array

Trying to update the background color of a td element with the code below. However, it seems that the code needs some adjustment as the color is not being applied. Any assistance or alternative solutions would be greatly appreciated. Snippet of PHP code: ...

Using AngularJS to retrieve JSON data with the HTTP module

I am a beginner in the world of angularjs and I need some guidance. Below is the code I have written: <!DOCTYPE HTML> <html ng-app="myapp"> <head> <meta charset="utf-8"> <title>Angularjs project</title> <script type= ...

Troubleshooting issue with AngularJS $http.get function failing to show retrieved

My data is showing up when I call the URL from dataSource, but it's not displaying when I use $http.get. I am sending this data to a dx-chart using a JsonResult from my controller. Below is the code snippet that includes my AngularJS file and MVC View ...

Combining Jquery Ajax with a Spring Boot controller results in the modification of dates

I am encountering an issue with my Ajax call: $.ajax({ type : 'GET', headers : { Accept : "application/json; charset=utf-8", "Content-Type" : "application/json; charset=utf-8" }, url : ...

Ways to identify changes in an HTML page following a form redirection

views.py class UpdatePasswordView(PasswordChangeView): form_class = UpdatePasswordForm success_url = reverse_lazy("login") login.html {% if passwordChanged %} <p style="color:green;">Your password has been successfu ...

"Restricting the height of a DIV container based on the size

Struggling with CSS as I try to get my #wrapper DIV to adjust its size based on its contents. I've experimented with 100% height and min-height, but nothing seems to work. Could it be related to relative versus absolute positioning? Here's a snip ...

Switching from using ngRouter to ui-router is a common

After purchasing an angularjs template for my application, I noticed that ngRouter was used instead of ui-router, which I am more comfortable with. So, I decided to switch to ui-router and update all the routes. However, I encountered some extra code in my ...

(Spotify Web API) Issue with Creating New Playlist - Received Error 403 (Forbidden) upon POST request

Looking for guidance on creating a new playlist using the Web API? Check out the notes here: When making a POST request to https://api.spotify.com/v1/users/{user_id}/playlists, make sure you include the access token and data with a content type of 'a ...

Repeatedly triggering the Jquery Dialog Event

When I open a calendar plugin in jquery dialog, I encounter a recurring issue. Every time I close and reopen the dialog, my calendar event onDayClick triggers multiple times – twice, thrice, and so on. <div id="show_calendar"> <div class="c ...

Real-time data updates not working in jQuery data table

I am currently dealing with a data table and using ajax to fetch data for display on my HTML DOM page. However, I have encountered an issue after implementing server-side processing for the data table. Even though I can successfully retrieve records in my ...