How can I get the attribute ID from the button? It returns undefined. I ask this because I will have many buttons with different ID like: edit-user-21 or edit-user-22
function edituser() {
var test = $(this).attr('id');
alert(test);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btn-primary" id="btn-edit-2" onclick="edituser()">Edit</button>
<div id="testdiv"></div>