Call the function by class and "this" selector it's the best way than using the inline onClick function called -> onclick=disable(i);
for multiple buttons
Note: use the same class name for all buttons that need a disabled function
Use jQuery CDN in the header or before your js script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
Method 1
HTML
<button type='button' class="btnClick" id = 'rbutton_"+i+"'>Click me</button>
JS
$('.btnClick').on('click', function(){
$(this).prop("disabled", true);
})
Method 2
$('.btnClick').on('click', function(){
disable(this.id)
})
function disable(id) {
$("#"+id).prop("disabled", true);
}
both methods will work perfectly on multiple button/element click.
#if there is any issue or wrong in my code, please comment below.