Is there a way to open multiple modals from various product tiles that share the same DOM structure?

I have implemented a customized boostrap modal in a single product on the PLP of my site. The HTML for this modal is as follows:

    <div class="modal size-variants fade pr-0" id="tumbler-size-modals" role="dialog">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-body">
                <p>Variants are loading..</p>
            </div>
        </div>
    </div>

To trigger this modal, I use the following a tag:

   <div class="more-sizes-link hide-mobile">
        <a href="javascript:void(0)" data-toggle="modal" data-target="#tumbler-size-modals">
            <isprint value="${Resource.msg('more.sizes.text.nonmobile', 'plp', null)}" />
        </a>
    </div>

Below is the CSS styling for the modal:

.modal-backdrop.show{
    opacity: 0;
}

.modal-open{
    overflow-y: visible;
}

.modal{
    position: absolute;
    top: unset;
    bottom: 23%;
    border: 1px solid $border-grey;
    background-color: $transparent-white;
}

While the modal functions correctly for one product tile on the PLP, it does not work when trying to open it from another tile while a modal is already open. How can I make the modal pop up from multiple product tiles simultaneously?

Refer to this image showing the modal successfully displayed on one product tile:

https://i.sstatic.net/WLbA6.png

This is the link that must be clicked to successfully open the modal for this specific product tile:

https://i.sstatic.net/w3cCf.png

I aim to open a new modal from the provided link while another one is already open. What steps should I take to achieve this?

Are there any specific considerations I need to keep in mind to achieve this functionality?

Although I am using Demandware ISML templates, I have omitted ISML tags as they are not relevant to the current question.

Answer №1

It is important that the ID and the corresponding data-target are unique. Consider adding a product ID or some other unique identifier to id="tumbler-size-modals"

Answer №2

Ensure that the ID is unique as per my previous comment. I inserted a sample variable into the ID, but be sure to customize it for your specific system.

    <div class="popup size-variants fade pr-0" id="cup-size-popups-${product_id}" role="dialog">
        <div class="popup-content">
            <!-- Content of the Popup -->
            <div class="popup-body">
                <p>Loading different variants...</p>
            </div>
        </div>
    </div>


   <div class="additional-sizes-link hide-on-mobile">
        <a href="javascript:void(0)" data-toggle="popup" data-target="#cup-size-popups-${product_id}">
            <isprint value="${Resource.msg('more.sizes.text.nonmobile', 'plp', null)}" />
        </a>
    </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

polygon with five or more sides

Can divs be created with shapes such as five or six corners? I am looking to create clickable zones on a map and any alternative methods would be greatly appreciated. ...

"Troubleshooting Issue: JavaScript and jQuery onClick Event Not Functioning Properly

Whenever I try to click on the "php1" div, nothing happens. The location.reload() function is only a placeholder used for testing if the onClick event is functioning properly. <div class="php-task"> <h1>PHP</h1> ...

The banner <div> appears in Chrome but is not visible in IE9

I'm facing an issue with a banner div under my navigation. It seems to show up in Google Chrome but doesn't appear in IE9. Below is the HTML and CSS code: HTML: <div class="content"> <div class="slide-banner"></div> ...

What is the best way to position an image in the center of the screen with uniform margins around it?

Could someone please help me figure this out? I've been attempting for some time but can't seem to make it work with the bottom margin. This website in the fashion industry showcases what I'm trying to achieve: It's designed to be resp ...

Steps for creating a horizontal card design

Looking to achieve a card style similar to this: http://prntscr.com/p6svjf How can I create this design to ensure it remains responsive? <div class="recent-work"> <img src="work/mercedes.png"> <h3>Modern website concept</h3&g ...

Modify the input based on the chosen option operation

I am working on a project where I have 3 select elements and when a user selects an option, the associated value should be displayed in an input field. I am trying to use a single function for these 3 selects, but I am facing some issues. Here is the HTML ...

"Mobile responsiveness issue: HTML email template table not aligning properly at the bottom on

Hello community, how is everyone doing? I'm currently working on creating my own HTML Email templates, but I'm facing some challenges with responsiveness. On desktop devices, the email looks like this: https://i.sstatic.net/X8vfu.png However, ...

I aim to decrease the number of decimal places in the code provided below

When working on an HTML page, I encountered a challenge with the decimal numbers displaying more positions than desired - for instance: 13.16 instead of 13.167. Despite my attempts to rectify this using the code snippet below, it is still not functioning ...

Hovering over a class list will modify various element IDs

Is there a way to change the height of an element with id = "header_nav" when hovering over the class "header_nav" li element? Here is the HTML Code: <div class="header_nav" id="header_nav"> <ul id="header_nav_mainmenu"> & ...

How to apply background images to LI elements using CSS

I've been experimenting with CSS-generated tabs to display an active state of an arrow underneath the tab. I tried using the background position properties to position the image for the hover event, but it would extend beyond the predefined boundaries ...

The toast feature is struggling to locate its designated div

Hey there, I've encountered an issue where the toast alert doesn't display on the page after I log in, but it does show up when I sign out. Any thoughts on why this is happening? I've tried various things like logging the toastLiveExample an ...

Steps to gather all the images within a directory

Take a look at this demo When you click on the "next" button, new images are loaded from the internet. In my application, all the images are stored in the img/image folder with names like 1.jpg, hi.png, etc. My question is, how can I display these image ...

CSS animation is supported on most browsers with the exception of Safari

I'm facing an issue with my animation that works fine on all browsers except Safari. I've tried using the autoprefix extension in VSCode to automatically add CSS vendor prefixes, but the animation still isn't functioning correctly. Here&apo ...

What is the reason behind the change in size and shape of the text when using "overflow: hidden"?

Check out this interactive demo using the provided HTML and CSS: You can view the demo by clicking on this link. /*CSS*/ .header { margin: 0px; padding: 0px; width: 100%; } .headertable { padding: 0px; margin: 0px; width: 100%; border-sp ...

Nuxtjs app experiences compatibility issues with Bootstrap templates

Greetings to all who come across this issue. I am currently working on a project using Nuxt.js with the Bootstrap template. The header and footer are displaying correctly, but the problem lies in the design of the body not showing up. https://i.stack.imgu ...

What is the method for defining CSS styles for child elements using the parent element's style attribute?

Here is an example: <div style="SET IMAGE ATTRIBUTES HERE!"> <img src="http://somesite.com/someimg.jpg"><br /> <img src="http://someothersite.com/someotherimg.jpg"><br /> ... </div> With my dynamic ASP.NET ...

Adjusting the <div> size for optimal display on iPhone and iPad screens

I am having an issue with my jQuery Mobile app. I have a page with a header and footer, and the main content consists of 4 images arranged in a 2x2 grid format. Since I couldn't get JM grid to work, I created my own grid using a div container. Here is ...

Control Over Fluid Grid Layouts

Apologies for reaching out, as I usually try to figure things out on my own. However, after spending hours reading through countless pages with no success, I am at my wit's end. I'm struggling to create a 4-column 'home' landing page f ...

Customize the appearance of the bootstrap nav-bar by assigning unique background colors to each dropdown menu

I'm looking to set unique background colors for each dropdown in a Bootstrap nav-bar using CSS. .mynavbar .dropdown ul.dropdown-menu:nth-child(1) { background-color: #59b057; } .mynavbar .dropdown ul.dropdown-menu:nth-child(2) { background-col ...

Dynamic content cannot have classes added to them using jQuery

When adding content dynamically, it is necessary to use an event handler for a parent element using on(). However, I am facing an issue where the class added with addClass on dynamically generated content disappears immediately. Let's take a look at ...