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

135
Views
Not able to call a method from InfoWindow in react js

I am trying to call a method on click of an element. The HTML is stored in a variable. It looks like below:

var cont = '<div class="infocontent" onClick="clickPoly('+index +')" style="width:100px;" >View More</div>';

const clickPoly = (index) => {
   var square = coordinates[index];
  
   if(square != undefined){
      square.dispatchEvent('click');
   }
}

clickPoly() should be called onclick of html above. But when I click on "View More", it shows "clickPoly is not defined".

Basically, I am showing multiple polygons on google map and on hover of each polygon I am showing infowindow. In infoWindow I need to show "View More" button and show relevant content.

You can see full code here

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

0

clickPoly needs to be defined on window.

window.clickPoly = (index) => {
  var square = coordinates[index];

  if (square != undefined) {
    square.dispatchEvent("click");
  }
};

alternatively, pass an HTMLElement to infowindow.setContent(element) and add the event in your component

var cont = '<div class="infocontent2" data-inx="'+index+'" onClick="clickPoly('+index +')" style="width:100px;" >View More</div>';

becomes

const cont = document.createElement('div').
cont.classList.add('infocontent2');
cont.addEventListener(() => clickPoly(index));
// add aria-label
cont.style.width = '100px';
cont.innerText = 'View More'
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!