次のコードを使用して、フォームの送信ボタンにイベントを添付しています。
$('form.manage-users-form').on('click','button.special',function() {
if ($(this).hasClass('selected')){
console.log('This user is already special');
} else {
$(this).parent().find('button').removeClass('selected');
$(this).addClass('selected');
var user_id = $(this).closest("form[id]").val();
console.log('This user is now special');
console.log(user_id);
}
return false;
});
また、フォームのIDも取得しようとしていることがわかりますが、コンソールを確認すると、が取得され(an empty string)
ます。それはなぜですか。フォームのIDを正しく取得するにはどうすればよいですか。