How to: Bootstrap button onclick events

We can easily add a onclick event to our button by selecting him via e.g. .querySelector() method then we can add our event listener to the selected node using the .addEventListener() method.

        
            
          <button type="button" class="btn btn-primary click">Click me!</button>
        
        
    
        
            
        document.querySelector('.click').addEventListener('click', (e) => {
          // Do whatever you want
          e.target.textContent = 'Clicked!';
        });