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

271
Views
Trying to add Eventlistener('click ') to a button Chrome extension

Hey guys im developing a Chrome extension. the site https://eportal.incometax.gov.in/iec/foservices/#/login

I want to display a modal when the button is clicked I can add a eventlistener to the button but it doesnt get triggered need help

<button _ngcontent-fes-c25="" class="large-button-primary width marTop16" disabled=""><span _ngcontent-fes-c25=""> Continue <!----><!----><img _ngcontent-fes-c25="" alt="disabled next icon" class="ng-star-inserted" src="https://static.incometax.gov.in/iec/foservices/assets/buttonIcons/nextIconDisabled.svg"><!----><!----></span></button>

enter image description here

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

0

In the content.js of your Chrome Extension, you'll want to create and append your modal element to the body of the page on load. You can do that with something like:

    const modal = document.createElement('h1');
    modal.innerText = 'This is the "modal"';
    modal.style.visibility = 'hidden';
    document.body.appendChild(modal);

Then add event listener to the button using CSS selectors and addEventListener

const button = document.querySelector('button.large-button-primary');
button.addEventListener('click', showModal);

And a function which changes your modal's visibility once it's clicked

const showModal = () => {
   modal.style.visibility = 'visible';
};

<button _ngcontent-fes-c25="" class="large-button-primary width marTop16">
    <span _ngcontent-fes-c25="">
        Continue
        <!----><!----><img
            _ngcontent-fes-c25=""
            alt="disabled next icon"
            class="ng-star-inserted"
            src="https://static.incometax.gov.in/iec/foservices/assets/buttonIcons/nextIconDisabled.svg"
        /><!----><!----></span
    >
</button>

<script>
    const button = document.querySelector('button.large-button-primary');
    const modal = document.createElement('h1');
    modal.innerText = 'This is the "modal"';
    modal.style.visibility = 'hidden';
    document.body.appendChild(modal);

    const showModal = () => {
        modal.style.visibility = 'visible';
    };

    button.addEventListener('click', showModal);
</script>

If the event listener isn't working, then that's probably because you're setting the button variable before the target button is even on screen, which means the querySelector is just returning undefined.

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!