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

Steps to turn off fancybox for mobile and show the full image instead

In this scenario... I am seeking a way to deactivate fancybox functionality on mobile devices. I have already discovered one method to disable it... And now I want to directly show the large image in the a href="xxx_large.jpg" instead of using the img src= ...

Creating a dynamic image carousel using jQuery

Today, I completed the jQuery course on Code Academy and am now trying to create an image slider using it. While I have a general idea of how it should work, I feel like I'm missing a key element. My goal is to have the slider continuously running whe ...

Combining two HTML tables in PHP: A step-by-step guide

I have two HTML tables that each contain three rows and one column. I am looking to combine them programmatically in order to create a single table with two columns and three rows. Is there a specific function or workaround that can help me achieve this? ...

Utilizing the Google Translate API within an ASP MVC framework to translate a div's content from English to Arabic

Currently, I am working on a small project that involves two divs: one for English and another for Arabic. Despite creating the project, I am encountering an issue with getting the translation from English to Arabic. Below is the code I have attempted, but ...

Showcasing diverse content with an Angular Dropdown Menu

I'm currently developing an angular application, and I've encountered a difficulty in displaying the user's selection from a dropdown menu. To elaborate, when a user selects a state like Texas, I want to show information such as the period, ...

Having trouble with my Slack Bot development due to an unexpected error

While attempting to create a Slack Bot in Node, I consistently encounter an error when running npm start in my terminal: The error seems to be located in the Vow.js file. Despite double-checking everything, I can't seem to pinpoint the issue. For gui ...

Using jQuery, how can I add value to every input when the option is changed?

I need help changing the values of all input:text elements based on selections from a select menu. Specifically, I want to change only the matched td.class values from the data-pset attribute inside the <select>. As a beginner in jQuery, I can only ...

Is there a way to showcase all the information in products while also organizing it in the same manner that I have?

I am looking to sort prices while displaying all the properties of products at the same time. DATA INPUT: const products = [ { "index": 0, "isSale": true, "isExclusive": false, "price": "Rs.2000", "productImage": "product-1.jpg", ...

Mobile Chrome allows users to utilize the IFrame player API for enhanced video

Currently, I am working on creating a mobile website where I plan to include some YouTube videos using the IFrame player API (https://developers.google.com/youtube/iframe_api_reference). My main goal is to have the video start playing only after the user ...

"Improprove your website's user experience by implementing Material UI Autocomplete with the

Recently, I experimented with the Autocomplete feature in Material UI. The focus was on adding an option when entering a new value. You can check out the demo by clicking on this link: https://codesandbox.io/s/material-demo-forked-lgeju?file=/demo.js One t ...

Incorporating HTML elements into a Jade template

Can HTML elements be passed into a jade file? For example, I want to insert text into the p element and nest some content inside the code element within the p element. JSON with string data var news = { one : { title : "Using JSON", body : "Us ...

Implementing jQuery - I Require Sequential Execution of Functions

I have a unique scenario where I need to ensure that two jQuery functions run in sequence when a form is submitted. The first function performs an AJAX call to check the database for any duplicate values and returns a response. It is crucial that the sec ...

Adjust the color of the active link on the page using Angular and CSS

I have a project that I need to modify by adding a sub menu that appears on every page but is only coded once. My goal is to highlight the link for the current page, all within one HTML snippet. Although the list renders correctly, I'm struggling to g ...

Ensuring Data Integrity in Angular JS Forms

I've been working on submitting a blank form that triggers custom error messages on mandatory fields. The validation is working perfectly, but I'm running into an issue when the form is loaded for the first time and the user clicks directly on th ...

AngularJS - activating $watch/$observe event handlers

I am looking for a way to trigger all $watch/$observe listeners, even if the watched/observed value has not changed. This would allow me to implement a "testing only" feature that refreshes the current page/view without requiring user interaction. I have a ...

Is it possible to disregard text formatting in Python when using Selenium?

I am experiencing an issue when trying to compare a name from my name string to a name in a webelement. For instance: Name format in my namestring (scraped from a website): Mcburnie Name in webelement: McBurnie The Xpath matching fails because the webe ...

Finding the current div based on the scrolling position can be achieved without the use of jQuery

Seeking assistance with a coding challenge. I have a solution in jQuery, but we require the solution in plain JavaScript or Angular. It seems like something is missing. Take a look at this fiddle. The objective is to highlight the corresponding left panel ...

Checking the types of arrays does not function properly within nested objects

let example: number[] = [1, 2, 3, 'a'] // this code block correctly fails due to an incorrect value type let example2 = { demo: 1, items: <number[]> ['a', 'b'], // this code block also correctly fails because of ...

Encountering a `ECONNREFUSED` error while attempting to dispatch an action in the

I have decided to convert my Nuxt application to SSR in order to utilize nuxtServerInit and asyncData. Below are the steps I followed during this conversion process. Removed ssr: false from nuxt.config.js Dispatched actions to initialize the store's ...

Guide on how to showcase the template by leveraging the roomList information with ngTemplateOutlet in Angular

TS roomList = [{ name: 'Room2' }] HTML <div class="Layout-body"> <ng-container *ngFor="let dt of roomList; index as i" [ngTemplateOutlet]="Room1" [ngTemplateOutletContext]="{ data: dt, i: i }&qu ...