Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Created August 6, 2021 18:47
Show Gist options
  • Save interactiveRob/938175ef487188c57d8f3006d849b6f9 to your computer and use it in GitHub Desktop.
Save interactiveRob/938175ef487188c57d8f3006d849b6f9 to your computer and use it in GitHub Desktop.
Javascript pass click to another button
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