MJ
asked on
JavaScript - Button Not Being Detected?
Regarding the JavaScript below, I'm not sure why when I click this button:
I have no idea why this is happening or how to fix? Thanks!
<button class="btn btn-mobile btn-grp-next btn-next-funding_amount mt-5" data-name="btn-grp-next" type="button"><span>CONTINUE</span> <i class="icon-arrow-thin-right"></i><i class="spinner"></i></button>
The following code doesn't detect the "CONTINUE" button being clicked for some reason? I do get into the function below but it is NOT passing the button element, I get the same result as clicking anywhere on the page and NOT the continue button. The listener is attached to document.body.
var saveInfosInSessionStorage = function(event) {
var target = event.target;
console.log("#### ==> target.type: " + target.type + " ===> target.dataset", target.dataset);
if (target.dataset && (target.type == "button")) {
var fType;
if (target.dataset.value) {
fType = target.dataset.value;
switch (fType) {
case "Fund Now":
...
break;
case "Fund Later":
...
break;
}
} else if (target.dataset.name) {
fType = target.dataset.name;
switch (fType) {
case "btn-grp-next":
console.log("============== CONTINUE BUTTON CLICKED =================");
break;
}
}
}
};
The console.log on line #4 shows the type as undefined and shows the data.set as "DOMStringMap" . So it acts as if I never clicked the "CONTINUE" button?I have no idea why this is happening or how to fix? Thanks!
Are the "Fund Now" and "Fund Later" buttons working? If so what is giving them a type of "button".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
You are welcome.