-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreturn-false-link-add-to-cart-button.js
52 lines (34 loc) · 1.1 KB
/
return-false-link-add-to-cart-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const submitBtn = document.querySelector('.product-form__submit');
submitBtn.addEventListener('click', (e) => {
e.preventDefault(); // disable default button behavior
window.location.href = '/pages/contact';
});
// Get all submit buttons
const submitBtns = document.querySelectorAll('.quick-add__submit');
if (submitBtns.length > 0) {
// Loop through each one
submitBtns.forEach(function(btn) {
// Attach listener
btn.addEventListener('click', (e) => {
e.preventDefault();
window.location.href = '/pages/contact';
});
});
} else {
// no submit buttons found
}
// Select by data attribute
const submitBtns = document.querySelectorAll('[data-cart-btn-override="true"]');
if (submitBtns.length > 0) {
submitBtns.forEach(function(btn) {
// Make button accessible
btn.setAttribute('role', 'link');
btn.setAttribute('tabindex', '0');
btn.addEventListener('click', (e) => {
e.preventDefault();
window.location.href = '/pages/contact';
});
});
} else {
// no buttons found
}