2948 explained code solutions for 75 technologies


chrome-extensionHow to listen for button click in popup script


<html>
  <body>
    <button>Click</button>
  </body>
    <script>
      document.querySelector('button').addEventListener('click', function() {
       console.log('Hi!');
      });
  </script>
</html>ctrl + c
button>Click</button

sample button to assign click event to

document.querySelector('button')

button selector

addEventListener

listen for specified event

'click'

we want to listen for clicks

console.log('Hi!')

do something here when button is clicked