Avatar of MJ
MJ
Flag for United States of America asked on

Detecting when button is clicked using Javascript based off of custom attribute name?

How would I detect when this button
<button class="btn btn-mobile btn-page-next btn-next-residency" data-name="btn-page-next" type="button">CONTINUE<i class="icon-arrow-thin-right"></i><i class="spinner"></i></button>

Open in new window

is clicked? I tried :
    function _dtmCheckContinue(){
        document.body.addEventListener('click', function(event) { 
	      if((event.target.dataset)&&(event.target.type == "button")){ 
             if(event.target.dataset.value == "btn-grp-next"){
             console.log("<=====> CONTINUE BUTTON CLICKED");
             }
          }
      
        });
    }

Open in new window

I can never get into the if statement on line 4 so obviously there is an issue there.

Thanks!
Web DevelopmentJavaScript* HTML 5

Avatar of undefined
Last Comment
MJ

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MJ

ASKER
Thank you sir! FYI.. This needed to be in a function .
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes