<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to addEventListener to a button in popup content of ArcGIS API for JS in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165268#M77040</link>
    <description>&lt;P&gt;Here is a sample adding a button to the popup content.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/abEPGxR?editors=1000" target="_blank" rel="noopener"&gt;https://codepen.io/odoe/pen/abEPGxR?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can either reuse the button you create, or be sure to remove the event listener if you don't&lt;/P&gt;&lt;P&gt;This is using the CustomContent of the PopupTemplate&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-CustomContent.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-CustomContent.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Apr 2022 18:10:48 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2022-04-18T18:10:48Z</dc:date>
    <item>
      <title>How to addEventListener to a button in popup content of ArcGIS API for JS</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165242#M77038</link>
      <description>&lt;P&gt;I have created a custom popup with the popupTemplate function with ArcGIS JS API 4.x&lt;/P&gt;&lt;P&gt;And i add a button in popup content by html.&lt;/P&gt;&lt;P&gt;but i can not addEventListener to a button in popup.&lt;/P&gt;&lt;P&gt;here is the way i am try to do now: ((the full code is here:&lt;A href="https://codepen.io/llllllllc/pen/mdpabGw" target="_blank" rel="nofollow noopener noreferrer"&gt;https://codepen.io/llllllllc/pen/mdpabGw&lt;/A&gt;&lt;A href="https://deepmaterialde.com/" target="_self"&gt;material&lt;/A&gt;))&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;return html to create button in popup content&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;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 =
                        "&amp;lt;input type='button' id='btn' value='CLICK'&amp;gt;";
                    return div;
                }&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;watch content change&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;view.popup.watch("content", (newValue, oldValue, propertyName, target) =&amp;gt; {......});&lt;/PRE&gt;&lt;P&gt;3.querySelector("#btn") then addEventListener but it fail ,and console.log(btn) show btn is null&lt;/P&gt;&lt;PRE&gt;const btn = document.querySelector("#btn");
console.log(btn)
btn.addEventListener(
    "click",
    function () {
        lert("HELLO WORLD!");
    },
   false
);a&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="F8v79.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/39142i1DD6382A39B7B28A/image-size/large?v=v2&amp;amp;px=999" role="button" title="F8v79.png" alt="F8v79.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2022 08:03:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165242#M77038</guid>
      <dc:creator>NoorMaria</dc:creator>
      <dc:date>2022-04-24T08:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to addEventListener to a button in popup content of ArcGIS API for JS</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165268#M77040</link>
      <description>&lt;P&gt;Here is a sample adding a button to the popup content.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/abEPGxR?editors=1000" target="_blank" rel="noopener"&gt;https://codepen.io/odoe/pen/abEPGxR?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can either reuse the button you create, or be sure to remove the event listener if you don't&lt;/P&gt;&lt;P&gt;This is using the CustomContent of the PopupTemplate&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-CustomContent.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-CustomContent.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 18:10:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165268#M77040</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-04-18T18:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to addEventListener to a button in popup content of ArcGIS API for JS</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165529#M77043</link>
      <description>&lt;P&gt;Along similar lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        function populationChange(feature) {
          const div = document.createElement("div");
          const btn = document.createElement("button")
          btn.innerHTML = 'Click Me'
          btn.onclick = function(props) {
            alert('hello world.')
          }
          return div.appendChild(btn)
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 04:52:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-addeventlistener-to-a-button-in-popup/m-p/1165529#M77043</guid>
      <dc:creator>sarahjones4</dc:creator>
      <dc:date>2022-04-19T04:52:56Z</dc:date>
    </item>
  </channel>
</rss>

