Created
August 6, 2021 18:47
-
-
Save interactiveRob/938175ef487188c57d8f3006d849b6f9 to your computer and use it in GitHub Desktop.
Javascript pass click to another button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function passClickToAnotherButton() { | |
| /* HTML be like: | |
| <button class="fake-button" send-click-to=".signature-m-pass"> | |
| Reserve now | |
| </button> | |
| */ | |
| //get all the fake buttons | |
| let buttons = Array.from(document.querySelectorAll('fake-button')); | |
| //loop through all the fake buttons | |
| buttons.map((button)=>{ | |
| //on click | |
| button.addEventListener('click', (e)=>{ | |
| //get the button that was clicked | |
| let btn = e.currentTarget; | |
| //select the real button | |
| let realButton = document.querySelector(`${btn.dataset.sendClickTo}`); | |
| //make sure it exists | |
| if(!realButton) return; | |
| //click the real button | |
| realButton.click(); | |
| }); | |
| });; | |
| } | |
| passClickToAnotherButton(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment