I have created a custom popup with the popupTemplate function with ArcGIS JS API 4.x
And i add a button in popup content by html.
but i can not addEventListener to a button in popup.
here is the way i am try to do now: ((the full code is here:https://codepen.io/llllllllc/pen/mdpabGwmaterial))
- return html to create button in popup content
const popupTemplate = {
// autocasts as new PopupTemplate()
title: "Population in {NAME}",
content: populationChange,
};
layer.popupTemplate = popupTemplate;
function populationChange(feature)
{
const div = document.createElement("div");
div.innerHTML =
"<input type='button' id='btn' value='CLICK'>";
return div;
}- watch content change
view.popup.watch("content", (newValue, oldValue, propertyName, target) => {......});3.querySelector("#btn") then addEventListener but it fail ,and console.log(btn) show btn is null
const btn = document.querySelector("#btn");
console.log(btn)
btn.addEventListener(
"click",
function () {
lert("HELLO WORLD!");
},
false
);a 