Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
JavaScript Modal not working properly for dynamic data load

when I close the 1st modal and open the 2nd modal, the 1st modal also remaining with the 2nd modal. same with 3rd one also. output image given

HTML CODE: 

<div class="modal" id="myModal">
      <div class="modal-dialog">
          <div class="modal-content" id="details-single">
          </div>
      </div>
</div>

JS CODE:

const itemDiv = document.getElementById('details-single');
const displayItem = item => {
    
    const div = document.createElement('div');
  div.innerHTML = `
 
            <div class="modal-header">
                <img class="product-image" src=${item.image}></img>
                <h5 class="modal-title">${item.title}</h5>
                <button class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
                ${item.description}
            </div>
            <div class="modal-footer">
                <button id="close" class="details" data-dismiss="modal">Close</button>
                <button onclick="addToCart(${item.id},${item.price})" id="addToCart-btn" 
                 class="add-btn">Add to Cart</button>
            </div>
        
  `;
  itemDiv.appendChild(div);
 
};

output imageoutput image 2

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!