Title: Capturing button click in JavaScript
Last modified: April 2, 2019

---

# Capturing button click in JavaScript

 *  Resolved [bobmeans](https://wordpress.org/support/users/bobmeans/)
 * (@bobmeans)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/capturing-button-click-in-javascript/)
 * Great plugin – thanks for making it!
    I’m trying to incorporate repeatable fields
   into a custom quote form. I have set up a document.addEventListener that looks
   at the class name to determine when to update the calculations with no problem.
   My problem is when the user clicks the wpcf7-field-group-remove button I can’t
   figure out how to grab that event. I used
 * document.addEventListener( ‘change’, function (event) {
    if (event.target.classList.
   contains(‘wpcf7-field-group-remove’)) { console.log(‘remove happened’); calculate(
   form, discount); } }); Any pointers on how to do this in JavaScript (not jQuery)?
   It looks like from the plugin code $( ‘body’ ).on( ‘click’, ‘.wpcf7-field-group-
   add, .wpcf7-field-group-remove’, function() {}); would work, but all the rest
   of my code is vanilla JS. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Felipe Elia](https://wordpress.org/support/users/felipeelia/)
 * (@felipeelia)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/capturing-button-click-in-javascript/#post-11937754)
 * Hi Bob!
 * First of all, sorry for taking this long to be back to you here.
 * As that is a custom jQuery event, unfortunately, you can’t rely on native addEventListener.
   I guess you could try to monitor changes to DOM using MutationObservers or something
   like that but that would be a bit hacky.
 * Before MutationObservers were a thing, you could use something like
 *     ```
       document.getElementsByClassName('wpcf7-field-groups')[0].addEventListener('DOMNodeRemoved', function( e ) {
       console.log( e );
       }, true );
       ```
   
 * but today that brings some performance issues.
 * I know you told your code is all vanilla JS but jQuery is being loaded anyway(
   the plugin needs it), so using jQuery there wouldn’t bring any additional code
   load.
 * Thanks!
 *  Plugin Author [Felipe Elia](https://wordpress.org/support/users/felipeelia/)
 * (@felipeelia)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/capturing-button-click-in-javascript/#post-12080908)
 * As it’s been more than a month since our last interaction here, I’m marking this
   topic as resolved. Let me know if you have any additional info or question. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Capturing button click in JavaScript’ is closed to new replies.

 * ![](https://ps.w.org/cf7-repeatable-fields/assets/icon-256x256.png?rev=2942207)
 * [Contact Form 7 - Repeatable Fields](https://wordpress.org/plugins/cf7-repeatable-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-repeatable-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-repeatable-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-repeatable-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-repeatable-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-repeatable-fields/reviews/)

## Tags

 * [EventListener](https://wordpress.org/support/topic-tag/eventlistener/)
 * [remove button](https://wordpress.org/support/topic-tag/remove-button/)

 * 2 replies
 * 2 participants
 * Last reply from: [Felipe Elia](https://wordpress.org/support/users/felipeelia/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/capturing-button-click-in-javascript/#post-12080908)
 * Status: resolved