I have a setup where I have two buttons on a page. On button 1 i'm triggering a click on button 2. On button 2 I have a function that runs when its clicked. But I need to tell in that function if it was button 1 or button 2 that was clicked.
Here is some basic code:
document.getElementById('btn2').onclick = function(event) {
// if button 1... else if button 2...
alert('I cant tell which button was clicked. '+ event.target.id +' was clicked.');
};
<div>
<button id="btn1" onclick="document.getElementById('btn2').click()">Button 1</button>
<button id="btn2">Button 2</button>
</div>
You will see that in the click function event.target.id will show the id of button 2 when button 1 is clicked.