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

104
Views
How can I get the exact clicked button event between two buttons in js?

I have two buttons with the same id but the difference is they have a unique data command, issue is the first button is clicking fine but the 2nd button is not responding.

        <li><button class="py-1 btn" id="command-btn" data-username=${
          view.attributes.nick
        } data-command="kick">Kick</button></li>

                <li><button class="py-1 btn" id="command-btn" data-username=${
          view.attributes.nick
        } data-command="ban">Ban</button></li>
                </ul>
              </div>
              `,
        );
      document
        .querySelector(`[data-msgid="${view.id}"] #command-btn`)
        ?.addEventListener('click', (event: any) => {
          const username = event.target.dataset.username;
          const command = event.target.dataset.command;
          console.log(username, command);

          const textarea: any = document.querySelector('.chat-textarea');
          const submitBtn: any = document.querySelector('.btn.send-button');
          textarea.value = `/${command} ${username}`;
          submitBtn.click();
        });

[data-msgid="${view.id}"] this means every div has a unique id, from that unique id I am getting the exact clicked button,

about 4 years ago · Santiago Trujillo
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!