Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag 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!
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Thank you sir! FYI.. This needed to be in a function .