There are three buttons. When I click on any of them - I want to see the number of clicked button in <span>
.
<button>1st button</button>
<button>2nd button</button>
<button>3rd button</button>
<span></span>
Firstly, I decided to use for-loop, but I know, that it keeps only last value.
for ( var i = 0; i< 3; i++ ) {
$('button:eq(' + i + ')').click(function() {
$('span').append(i + 'button was clicked');
});
}
Maybe, $.each()
function will help me?