I have 2 buttons. I want to detect if the previous button clicked then on 2nd button click it should display some data otherwise if user is directly clicking on the second button, it should display an alert(please click the previous button first). I have tried to do so but not able to detect whether the 1st button is clicked or not :-(
HTML
<input type="button" id="btn1" value="button1"></input>
<input type="button" id="btn2" value="button2"></input>
JavaScript
$('#btn1').click(function(){
alert('Button 1 Clicked');
});
$('#btn2').click(function(event) {
var inputButton = document.getElementsByTagName('input');
var $target = $(event.target);
if( $target.is(inputButton[1]) ) {
alert("Please click the 1st Button first");
} else{
alert('Button 2 Clicked');
}
});