<?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: OnClick function not working on all buttons in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843498#M42122</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/505816"&gt;@Mrafey&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for your question. Can you add your code to your post, please? You can use the code block tool to help with formatting. Troubleshooting code from screenshots is hard to impossible for our community members to help with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks! — Jaycee&lt;/P&gt;</description>
    <pubDate>Fri, 01 Sep 2023 07:47:19 GMT</pubDate>
    <dc:creator>Jaycee_Lewis</dc:creator>
    <dc:date>2023-09-01T07:47:19Z</dc:date>
    <item>
      <title>OnClick function not working on all buttons</title>
      <link>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843332#M42121</link>
      <description>&lt;P&gt;I have developed action cards that have a "copy text" button on them, that when clicked copy the text that is in the component.&lt;BR /&gt;&lt;BR /&gt;Here is my HubL + HTML code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2023-08-31 at 4.48.19 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/98124iCE3DA81931FCB29D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2023-08-31 at 4.48.19 PM.png" alt="Screen Shot 2023-08-31 at 4.48.19 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Following is my JS Code:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2023-08-31 at 4.49.46 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/98125iA145680291B3A9C6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2023-08-31 at 4.49.46 PM.png" alt="Screen Shot 2023-08-31 at 4.49.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;Whats odd is when I run this code, only one of the buttons "Copy text" works. So for instance if I have three action cards on my page, only the first action card's "Copy Text" button works and the other two dont.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Anyone have any idea what it could be?&lt;BR /&gt;&lt;BR /&gt;Thanks!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 20:53:43 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843332#M42121</guid>
      <dc:creator>Mrafey</dc:creator>
      <dc:date>2023-08-31T20:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: OnClick function not working on all buttons</title>
      <link>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843498#M42122</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/505816"&gt;@Mrafey&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for your question. Can you add your code to your post, please? You can use the code block tool to help with formatting. Troubleshooting code from screenshots is hard to impossible for our community members to help with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks! — Jaycee&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 07:47:19 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843498#M42122</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-09-01T07:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: OnClick function not working on all buttons</title>
      <link>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843505#M42123</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/505816"&gt;@Mrafey&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The method "getElementById" returns one element&lt;/P&gt;
&lt;P&gt;even if there are multiple elements with the same ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about use `class` ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;exmaple: (not tested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// Add click event all [copyBtn]
const copyBtns = Array.from(document.querySelectorAll('.copyBtn'));
copyBtns.forEach((copyBtn, index) =&amp;gt; {
    copyBtn.addEventListener('click', () =&amp;gt; {
        // Get the text corresponding to the copy button
        const actionDescription = document.querySelectorAll('.copy-desc-text')[index];
        const copyTxt = actionDescription.textContent;
        navigator.clipboard.writeText(copyTxt);
        ...
    });
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 07:57:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/OnClick-function-not-working-on-all-buttons/m-p/843505#M42123</guid>
      <dc:creator>skimura</dc:creator>
      <dc:date>2023-09-01T07:57:48Z</dc:date>
    </item>
  </channel>
</rss>

