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

141
Views
Open distant bootstrap modal
let readcomment = event.target.closest(".read-comment");
        let dataAttribute = readcomment.getAttribute('data-id');
        let url = "../comments/" + dataAttribute + "/";
        fetch(url)
            .then(function (response) {
                return response.text();
            })
            .then(function (data) {
                console.log(data)
            })
            .catch(function (error) {
                console.log(error);
            });

When "read-comment" is clicked, I get the data-id value and build the URL variable.

I get the data from the URL with JS fetch function.

I would like to render fetched data in a bootstrap modal (using bootstrap 5)

On bootstrap, documentation says we can create a modal with

var myModal = new bootstrap.Modal(document.getElementById('myModal'), options)

In my project, the "Read-comment" button is in the first file and "myModal" content is in a second different file, and then when the button is clicked, the previous code return :

TypeError: this._element is undefined"

The problem is "document.getelementbyid("myModal")" returns null because myModal is in another file that is not loaded on the first page.

How should I do?

Thank you for your help.

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!