Repeated information displayed in modal pop-ups

HTML

<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

      <div class="popup" data-popup="popup-1">
        <div class="popup-inner">
        <h2>Unbelievable! Check this Out! (Popup #1)</h2>
        <p>Per Serving: 5g Energy: 20kcal Protein: 0.0g Total Fat: 0.0g Saturated Fat: 0.0g Carbohydrates: 0.0g Package Size: 1 x 24 x 350g</p>
        <p><a data-popup-close="popup-1" href="#">Close</a></p>
        <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
         </div>
      </div>

    <a class="btn" data-popup-open="popup-1" href="#">Quick Inquiry</a>

      <div class="popup" data-popup="popup-1">
        <div class="popup-inner">
        <h2>This One Won't Disappoint (Popup #1)</h2>
        <p>Another set of data that will not disappoint.</p>
        <p><a data-popup-close="popup-1" href="#">Close</a></p>
        <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
       </div>
     </div>
    

CSS:

/* Outer */
    .popup {
      width:100%;
      height:100%;
      display:none;
      position:fixed;
      top:0px;
      left:0px;
      background:rgba(0,0,0,0.75);
    }

    /* Inner */
    .popup-inner {
      max-width:700px;
      width:90%;
      padding:40px;
      position:absolute;
      top:50%;
      left:50%;
      -webkit-transform:translate(-50%, -50%);
      transform:translate(-50%, -50%);
      box-shadow:0px 2px 6px rgba(0,0,0,1);
      border-radius:3px;
      background:#fff;
    }

    /* Close Button */
    .popup-close {
      width:30px;
      height:30px;
      padding-top:4px;
      display:inline-block;
      position:absolute;
      top:0px;
      right:0px;
      transition:ease 0.25s all;
      -webkit-transform:translate(50%, -50%);
      transform:translate(50%, -50%);
      border-radius:1000px;
      background:rgba(0,0,0,0.8);
      font-family:Arial, Sans-Serif;
      font-size:20px;
      text-align:center;
      line-height:100%;
      color:#fff;
    }

    .popup-close:hover {
      -webkit-transform:translate(50%, -50%) rotate(180deg);
      transform:translate(50%, -50%) rotate(180deg);
      background:rgba(0,0,0,1);
      text-decoration:none;
    }
    

jQuery:

$(function() {
    //----- OPEN
    $('[data-popup-open]').on('click', function(e)  {
        var targeted_popup_class = jQuery(this).attr('data-popup-open');
        $('[data-popup="' + targeted_popup_class + '"]').fadeIn(350);

        e.preventDefault();
    });

    //----- CLOSE
    $('[data-popup-close]').on('click', function(e)  {
        var targeted_popup_class = jQuery(this).attr('data-popup-close');
        $('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);

        e.preventDefault();
    });
    });
    

This code functions as expected but seems to have an issue with displaying the content in the second popup. Even after trying different jQuery popup implementations, the data inside the popup remains unchanged when navigating to the next one. How can this be resolved?

Answer №1

To customize the popups, you need to modify the data-popup attributes accordingly. For example, use popup-1 for the first popup and popup-2 for the second:

<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

  <div class="popup" data-popup="popup-1">
    <div class="popup-inner">
    <h2>Exciting Stuff Here! (Popup #1)</h2>
    <p>Serving Size: 5g   Energy : 20kcal Protein : 0.0g Fat­Total : 0.0g  Saturated &nbsp; 0.0g  Carbohydrate : 0.0g Package Size : 1 x 24 x 350 g</p>
    <p><a data-popup-close="popup-1" href="#">Close</a></p>
    <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
     </div>
  </div>

<a class="btn" data-popup-open="popup-2" href="#">Quick inquiry</a>

  <div class="popup" data-popup="popup-2">
    <div class="popup-inner">
    <h2>This Feature Isn't Working(Popup #2)</h2>
    <p>Additional information that won't display</p>
    <p><a data-popup-close="popup-2" href="#">Close</a></p>
    <a class="popup-close" data-popup-close="popup-2" href="#">x</a>
   </div>
 </div>

Answer №2

If you want your webpage to function properly, make sure to alter the value of data-popup-open on the second <a> tag and match it with the corresponding data-popup attribute on the second <div class="popup">. Ensure that your JavaScript and CSS codes are correctly implemented.

<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

<div class="popup" data-popup="popup-1">
  <div class="popup-inner">
    <h2>Wow! This is Awesome! (Popup #1)</h2>
    <p>Per Serve : 5g Energy : 20kcal Protein : 0.0g Fat­Total : 0.0g Saturated &nbsp; 0.0g Carbohydrate : 0.0g Package Size : 1 x 24 x 350 g</p>
    <p><a data-popup-close="popup-1" href="#">Close</a>
    </p>
    <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
  </div>
</div>

<!-- Changed data-popup-open to popup-2 -->
<a class="btn" data-popup-open="popup-2" href="#">Quick inquiry</a>
<!-- Change data-popup to popup-2 -->
<div class="popup" data-popup="popup-2">
  <div class="popup-inner">
    <h2>This is the one that wont work(Popup #1)</h2>
    <p>Another data that wont appear</p>
    <p><a data-popup-close="popup-1" href="#">Close</a>
    </p>
    <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
  </div>
</div>

Answer №3

Make sure to update the data-popup-open and data-popup attributes in the second modal section

<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

  <div class="popup" data-popup="popup-1">
    <div class="popup-inner">
    <h2>Wow! This is Awesome! (Popup #1)</h2>
    <p>Per Serve : 5g   Energy : 20kcal Protein : 0.0g Fat­Total : 0.0g  Saturated &nbsp; 0.0g  Carbohydrate : 0.0g Package Size : 1 x 24 x 350 g</p>
    <p><a data-popup-close="popup-1" href="#">Close</a></p>
    <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
     </div>
  </div>

<a class="btn" data-popup-open="popup-2" href="#">Quick inquiry</a>

  <div class="popup" data-popup="popup-2">
    <div class="popup-inner">
    <h2>This one needs adjustments(Popup #2)</h2>
    <p>Other data that should be modified</p>
    <p><a data-popup-close="popup-2" href="#">Close</a></p>
    <a class="popup-close" data-popup-close="popup-2" href="#">x</a>
   </div>
 </div>

https://jsfiddle.net/873ww7pj/

Answer №4

Take a look at this code snippet, it's fully functional! To create more modals, simply change the ID or popup name.

$(function() {
//----- OPEN
$('[data-popup-open]').on('click', function(e)  {
    var targeted_popup_class = jQuery(this).attr('data-popup-open');
    $('[data-popup="' + targeted_popup_class + '"]').fadeIn(350);

    e.preventDefault();
});

//----- CLOSE
$('[data-popup-close]').on('click', function(e)  {
    var targeted_popup_class = jQuery(this).attr('data-popup-close');
    $('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);

    e.preventDefault();
});
});
/* Outer */
.popup {
width:100%;
height:100%;
display:none;
position:fixed;
top:0px;
left:0px;
background:rgba(0,0,0,0.75);
}

/* Inner */
 .popup-inner {
max-width:700px;
width:90%;
padding:40px;
position:absolute;
top:50%;
left:50%;
-webkit-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
box-shadow:0px 2px 6px rgba(0,0,0,1);
border-radius:3px;
background:#fff;
}

/* Close Button */
.popup-close {
width:30px;
height:30px;
padding-top:4px;
display:inline-block;
position:absolute;
top:0px;
right:0px;
transition:ease 0.25s all;
-webkit-transform:translate(50%, -50%);
transform:translate(50%, -50%);
border-radius:1000px;
background:rgba(0,0,0,0.8);
font-family:Arial, Sans-Serif;
font-size:20px;
text-align:center;
line-height:100%;
color:#fff;
}

.popup-close:hover {
-webkit-transform:translate(50%, -50%) rotate(180deg);
transform:translate(50%, -50%) rotate(180deg);
background:rgba(0,0,0,1);
text-decoration:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

  <div class="popup" data-popup="popup-1">
    <div class="popup-inner">
    <h2>Wow! This is Awesome! (Popup #1)</h2>
    <p>Per Serve : 5g   Energy : 20kcal Protein : 0.0g Fat­Total : 0.0g  Saturated &nbsp; 0.0g  Carbohydrate : 0.0g Package Size : 1 x 24 x 350 g</p>
    <p><a data-popup-close="popup-1" href="#">Close</a></p>
    <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
     </div>
  </div>

<a class="btn" data-popup-open="popup-2" href="#">Quick inquiry</a>
  <div class="popup" data-popup="popup-2">
    <div class="popup-inner">
    <h2>This is the one that wont work(Popup #1)</h2>
    <p>Another data that wont appear</p>
    <p><a data-popup-close="popup-2" href="#">Close</a></p>
    <a class="popup-close" data-popup-close="popup-2" href="#">x</a>
   </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

Looking for the function to activate when the enter key is pressed

I have a search box which is a text type and has a click button that initiates the Find() function. How can I enable searching by pressing Enter inside the textbox? ...

Exploring a Collection in Meteor: Working with an Object

This issue has been plaguing me for some time now, and it's starting to really get on my nerves. To put it simply: How can we iterate over an object within a collection in a template? Each entry in the collection typically looks like this: { "_i ...

The app.get() function seems to be inactive and not triggering in the Express application

I am currently exploring the MEAN stack and experimenting with implementing express. I've encountered a peculiar issue where I keep receiving a 404 error when trying to access a specific path that I have configured for the app object to manage. Oddly ...

Customize the Kendo UI by integrating it with HTML tables and dropdown lists

I am trying to utilize an HTML table as the data source for kendo-ui jQuery, and also enable inline editing with a drop-down list. To achieve this, I have written the code below: However, my issue arises when a user double clicks on a row of the table to ...

Hide Navbar when clicking on menu item

I'm struggling with finding a solution to this issue, as I am unsure of how to proceed. The problem I am facing is that when I click on an item, the router-view changes correctly, but the menu remains open. I would like it to close after a click. ...

Show a dynamic Swiper carousel upon selecting a thumbnail in an image gallery

I am in the process of creating a thumbnail gallery that includes a slider feature using Swiper. The default setup has the slider hidden, and once an image is clicked, the slider should appear with the selected image. To close the slider and return to the ...

Exploring the Response Object in Express JS: A Comprehensive Guide

I'm currently using Express version 4.13.4. My goal is to access and examine the res object. However, when I try to use console.log() on it, the output is too lengthy to display properly in a command window. I attempted to utilize jsonfile to save i ...

The element "center" is not a recognized HTML tag in Angular 4

The center tag is not functioning and it says that center is an unknown element. <center> <a><img class="placeholder_img" src="img/placeholder.png"></a> </center> When I used the above HTML tags, it stated that "center i ...

What is the most effective method for dynamically showcasing buttons in AngularJS?

Hello all, I'm currently learning AngularJS and I was wondering if anyone could recommend the simplest and most effective method for dynamically displaying links from AngularJS to HTML. I am looking to display a variable number of buttons in my HTML ...

"Receiving an 'undefined index' error when attempting to post in Ajax with

Need help with sending data from client to server using AJAX in PHP. I am facing an issue when trying the following code: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascrip ...

Communicating data transfer between two Node.js servers through the use of the Node Serial Port technology

How can I send the message "Hello world" from one nodejs server to another using node-serialport? I have confirmed that the radios connecting the two servers are properly connected as they are displaying buffer information after running my current code. ...

Leveraging the Power of JavaScript within Angular 12

Currently, I am in the process of learning how to utilize Angular 12 and am attempting to create a sidenav. While I am aware that I can use angular material for this task, I would prefer not to incorporate the associated CSS. My goal is to integrate this ...

Tips for executing a never-ending blocking operation in NodeJS?

Currently, I have a collection of API endpoints within Express. One specific endpoint triggers a lengthy process that hinders the flow of other incoming requests in Express. I am determined to transform this process into a non-blocking one. In order to ga ...

Access information from AJAX request beyond the success function

Currently, I am utilizing beautiful soup to extract information from a webpage. A user inputs their zip code upon arriving at the main page of my site, triggering an AJAX request to Django for data retrieval based on the input. The corresponding JavaScript ...

I'm encountering an issue with my React master component not being able to locate the

I am having trouble importing a component in my APP.js file. I have been attempting to bring MainComponent into the app.js component, but I am facing difficulties in fetching the component. Any assistance in resolving this issue would be greatly apprecia ...

The method for transforming all headers into permalinks with jquery/javascript

I am looking for a way to transform all headers on a page into clickable permalinks using jQuery or JavaScript. Here is the HTML code: $('h3').each(function() { var id = $(this).attr('id'); if (id) { //Check if the element has a ...

Encountering a problem with the Ionic Modal Slider: unable to locate the matching element associated with delegate-handle= when using $

I am encountering a problem with my Ionic application that features multiple Angular controllers. Specifically, I have a LoginCtrl and RegisterCtrl controller set up. The issue arises when I try to trigger a modal with a slider from the RegisterCtrl by usi ...

What is the point of utilizing angular.extend in this situation?

After inheriting a codebase, I stumbled upon the following code snippet (with some parameters simplified and anonymized): /** * @param {float} num1 * @param {string} str1 * @param {string} str2 * @param {boolean} flag & @return (object) */ sr ...

Is it possible to integrate two calendars into the `DatePicker` component of MUI?

The <DateRangePicker/> component from MUI has a prop called calendars which determines the number of calendars displayed inside the component popup. Here is an example: If the calendars prop has a value of "3", it will look like this: https://i.sta ...

Having trouble selecting a default option in a dynamically populated select dropdown using ng-model in the dropdown

For my Angularjs application, I needed to dynamically return a select drop down with its selected option. To accomplish this, I implemented the following function: function getCellRendererMapping(data) { if (data.order == 6) { return funct ...