View
<?php $no=1; foreach($result as $r){?>
<span><?php echo $r['id'];?></span><span><?php echo $r['name'];?></span>
<button class="btn btn-success" id="<?php echo $no?>">Add</button>
<?php $no++;}?>
This php code will display 5 buttons with the different id (1,2,3 and so on). What I want to happen is when I click any of the 5 buttons the jQuery function will show its id. I have this code.
var btn = $('.btn-success').attr('id');
$('#'+btn).click(function(){
alert(btn);
}
but, it only appears for the first id.