What is the best way to showcase a variable amount of information using just one popup box?

I currently have a section dedicated to showcasing various projects. Each project is represented by an image, and upon clicking on it, a popup box will appear with more detailed information about that specific project.

Issue at Hand

The challenge I am facing is how to utilize a single popup box for an indefinite number of projects. Essentially, I want the same popup box, styled with CSS, to display information corresponding to whichever project is clicked.

For instance:

Project Gallery

When a user clicks on any project

As illustrated above, the popup box contains identical information regardless of the project being clicked on.

Here's a snippet of the HTML code used to display the images:

<!-- ========= li ========= -->
<li>
  <div class="item-img">
    <img alt="Ink Transition Effect" src="img/HQCLogo.svg">
  </div>
  <div class="item-info light-bg" style="background-color: rgb(241, 241, 241)">
    <a href="http://www.hqcglobal.com"><em>HQCGlobal</em></a>  <i class="date">March 12, 2015</i>
  </div>
  <div class="feed" id="feed1">
    <div class="heart" id="like1" rel="like"></div>
    <div class="likeCount" id="LikeCount1"></div>
  </div>
</li>
<!-- ========= li ========= -->

Furthermore, here is the code for the reusable popup box:

<div class="java-popup" role="alert">
  <div class="java-popup-container">
    <a href="#0" class="java-popup-close img-replace">Close</a>
    <div class="left-box">
      <img src="img/HQCLogo.svg" width="750px" />
    </div>
    <div class="right-description-box">
      <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi...
       (Text shortened for brevity)
      
      </p>
    </div>
  </div>
  <!-- cd-popup-container -->
</div>
<!-- cd-popup -->

To trigger the opening of the popup box upon clicking on a project, JavaScript has been utilized:

  // Open popup box
  $('.item-img').on('click', function(event) {
    event.preventDefault();
    $('.java-popup').addClass('is-visible');
  });
  //close popup
  $('.java-popup').on('click', function(event) {
    if ($(event.target).is('.java-popup-close') || $(event.target).is(
      '.java-popup')) {
      event.preventDefault();
      $(this).removeClass('is-visible');
    }
  });

My main query revolves around how I can dynamically populate the popup box with unique information based on the project clicked.

Regards, Naseeb

Answer №1

The .java-popup element in your HTML code functions as a standard division that appears as a pop-up by utilizing the CSS properties position: fixed/absolute for flexible positioning on the screen and z-index to keep it above other elements in the DOM.

To add new HTML content within these sub-divisions, you can employ typical JavaScript/jQuery methods like .html(), .append(), .text(), among others.

$('#pop1').click(function(){
   $('#overlay').show();
   $('.java-popup').fadeIn();
});

$('#pop2').click(function(){
   $('.left-box').html('<img src="http://placekitten.com/50/50" />');
   $('.right-description-box').html('You can include various types of HTML here - divs, images, styled p tags, etc.');
   $('#overlay').show();
   $('.java-popup').fadeIn();
});

$('.java-popup-close').click(function(){
   $('#overlay').fadeOut();
   $('.java-popup').fadeOut();
});
*{position:relative;box-sizing:border-box;}
#overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:black;opacity:0.7;z-index:98;display:none;}
.java-popup{display:none;position:fixed;top:20px;left:50px;width:450px;height:250px;background:white;overflow:none;z-index:99;}

.java-popup-container{overflow:hidden;}
  .java-popup-close{position:absolute;right:20px;top:0;z-index:999;}
  .left-box{float:left;width:60px;height:100%;}
  .right-description-box{float:left;width:390px;height:100%;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div id="overlay"></div>
<div class="java-popup" role="alert">
  <div class="java-popup-container">
    <a href="#0" class="java-popup-close img-replace">Close</a>
    <div class="left-box">
      <img src="img/HQCLogo.svg" width="750px" />
    </div>
    <div class="right-description-box">
      <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
        in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        <br />
        <br />Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
        irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>
  </div>
  <!-- cd-popup-container -->
</div>
<!-- cd-popup -->
<button id="pop1">Show popup</button>
<button id="pop2">Change Info in Popup</button>

Answer №2

Unfortunately, I lack 50 reputation points to leave a comment, but consider utilizing a modal for this situation. Bootstrap offers a user-friendly modal system, and W3Schools provides a helpful tutorial on how to implement them.
Check out the W3Schools tutorial on Bootstrap modals here: http://www.w3schools.com/bootstrap/bootstrap_modal.asp

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

Transmitting the identification number of a post with the help of J

I am currently working on a while loop in PHP that fetches associated results from a query and displays them within a class identified by the user who created the post. My goal is to send the id of the class to PHP, similar to how I am sending the num vari ...

Retrieve data from the api

Can someone provide the JavaScript code to loop through an API, extract the coordinates/address, and map it? Here is a simple demonstration of fetching the API data: const fetch = require("node-fetch"); fetch('url').then(function (resp ...

Troubleshooting issue with ellipsis functionality in Bootstrap using flex layout

I have been struggling to include ellipsis after displaying 2 lines of icons. I have tried different approaches and modifications, but nothing seems to work. Seeking assistance from experts to tackle this issue, your feedback is highly appreciated. .elli ...

Sending an array of objects to a nested component

Currently, I am tackling a front-end challenge in a bootcamp project and facing an issue while passing an object array to a child component. To troubleshoot, I am generating a variable array to test out components. While utilizing a map on the array withi ...

How to Execute a jQuery Ajax Request from the Master Page?

Why do I keep encountering a 500 error every time I attempt a simple ajax call using jquery to a web service on my site from the master page? Is it uncommon to make an ajax call from a master page, or am I just sleep-deprived and losing my mind? Here is a ...

How come my label and input are showing up in my navigation bar?

For my assignment, I am designing a website layout and facing an issue where the text appears behind the navigation bar instead of below it. I have tried adjusting the margin-bottom to 50px with important tags and setting the nav bar as static. Despite tr ...

Check the document's location if the page contains a class with a specific value

I am encountering an issue while using PHPMailer. I am trying to redirect the page after submitting a form and display a success popup window. After successfully submitting the form, a message is displayed in a popup window (JavaScript adds a class ' ...

Issue with long text in a resizable table using jQuery tablesorter 2.31.1

My issue is that when I try to resize the columns in tablesorter, they snap back into place. The column width set with resizable_widths does not apply correctly until a column is manually resized. Despite setting the width of all cells to 120px, any cells ...

Sending Information to MONGODB through a POST call

Utilizing npm request to inject data into MongoDB like a direct injection using form variables yields the following output in the browser upon clicking the submit button: FORM DATA Here is the script used to insert credentials into the database: request. ...

Embracing the beauty of incorporating nested quotations

I've been experimenting with jquery's append functions lately. I'm adding a substantial amount of html, specifically a button with an onclick event function. It might sound complicated, but due to some technical restrictions, this is my onl ...

Why does the diamond symbol appear distorted on my iPhone screen?

My website is similar to SO where moderators have a diamond sign at the end of their name. However, I am facing an issue on my iPhone where the diamond sign looks red and distorted (on Chrome it appears normal). https://i.sstatic.net/RnpyP.jpg As you can ...

How can I store all selected dropdown values in the URL parameters whenever a dropdown option is changed?

In mypage.php, I have set up three drop-down menus: <select name='vehicle'> <option value=''>Select</option> <option value='bus'>Bus</option> <option value='bike'>Bike</o ...

Should the HTML inputs be positioned within the label or placed outside of it?

Check out this site for some on/off switches: <div class="onoffswitch"> <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked> <label class="onoffswitch-label" for="myonoffswitch"> < ...

The Bootstrap Modal consistently displays the initial record, regardless of the row that is selected

I'm having an issue with a table that displays records and two buttons for edit and delete. When I click on the buttons, a Bootstrap modal opens, but it always displays the first record regardless of which row is clicked. <!DOCTYPE html> <htm ...

Creating a uniform mobile version for all smartphones on a website

My website, www.sauleezy.altervista.org, is experiencing an issue that I have been unable to resolve. I have set up two different .css files for desktop (style.css) and mobile (handheld.css). In my index file, I included the following code: <meta name= ...

Guide to positioning buttons in the center of an image using Bootstrap 4

I need help centering buttons within two adjacent responsive images. The buttons are currently positioned below the images. Here is my code: <!--LAB1--> <div class="row"> <div class="col-lg-2 col-md-6 col-lg-6"> <div class="view overl ...

Convert Initialization Vector (IV) to hexadecimal format, save it into a file, later read it from the file, then convert the hexadecimal to binary. The process continues with various operations in NodeJS

I am attempting to convert an Initialization Vector into a hexadecimal string, and then reverse the process back to binary. However, when I try to display the output in the console, it is showing the following: fIV: undefinedundefinedundefinedundefinedunde ...

Include onload to element without running it in Puppeteer

I am currently developing a web scraping tool using Puppeteer. Once the webpage is fully loaded, I need to update the HTML code and include an onload event for certain elements. The issue is that in Puppeteer, the onload event is actually triggered automa ...

Issue when trying to retrieve the length of an array from a JSON AJAX request in JavaScript when the array is not an

Having an issue with determining the length of an array that is not initialized in the var variable = new Array(); format. Check out the code snippet below: var inx; var qns; var qis; var ncs; var nzs; var tps; function display_question() { $( "#q ...

Utilizing angular.element().bind with dynamically created element identifiers

I am trying to access an element with a randomly generated ID from my controller. Here is the code snippet: self.componentId = '#' + Math.random().toString(); angular.element(self.componentId).bind('scroll', function () { if (angu ...