Reputation: 143
I'm trying to get the value of my data-userid but it's not working.
Button: id }}" data-toggle="modal" data-target="#modal-delete"> DELETE Code:
$('.delete-btn').click(function(){
userId = $(this).dataset.userId;
alert(userId);
});
But attr is working.
$('.delete-btn').click(function(){
userId = $(this).attr('data-userid');
alert(userId);
});
Upvotes: 2
Views: 1582
Reputation: 115222
Here $(this)
is a jQuery object , dataset
is the property of dom object so just use this
instead
$('.delete-btn').click(function(){
userId = this.dataset.userId;
alert(userId);
});
Or use data()
method
$('.delete-btn').click(function(){
userId = $(this).data('userId');
alert(userId);
});
Upvotes: 2
Reputation: 1290
$('.delete-btn').click(function(){
userId = $(this).data('userid');
alert(userId);
});
Upvotes: 0