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

158
Views
How to get dynamic popover element after inserted to DOM?

I am having a simple popover with a dynamic canvas(snippet below):

$('[data-toggle="popover"]').popover({
  html: true,
  content: '<canvas id="myChart" width="400" height="400"></canvas>',
}).on('shown.bs.popover', function() {

  const ctx = document.getElementById("myChart")
  alert(ctx.id)

I don't seem to be able to get the myChart element, getElementById returns a null object. I am assuming this has to do with the fact that the canvas element is not inserted into the DOM yet, but since I have little knowledge about Javascript, I am not sure how to fix that issue in order to be able to get the canvas object and display a chart on it.

Any suggestions?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I discovered what was needed to make it work, so unexpected. I needed to turn off auto sanitize with:

        $('[data-toggle="popover"]').popover({
          html: true,
          content: '<canvas id="myChart" width="400" height="400"></canvas>',
          sanitize: false
        }).on('shown.bs.popover', function() {
about 4 years ago · Juan Pablo Isaza Report
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!