Andrei
Andrei

Reputation: 65

jQuery on click gets the same data attribute value every time

I have the following code:

$('body').on('click','#confirm_remove',function(){
  alert($(this).data('whattoremove'));
});

The #confirm_remove is a button id inside a bootstrap modal, who's data attribute (whattoremove) gets updated every time the modal opens - this is verified, but for some reason the data in the jQuery function has the same value on every click - this is the value of the first time it was clicked.

Any ideas on how to fix this.

Upvotes: 0

Views: 77

Answers (1)

mscdeveloper
mscdeveloper

Reputation: 2889

try this:

$('#confirm_remove').click(function(){
  alert( $('#confirm_remove').attr('whattoremove') );
});

Upvotes: 1

Related Questions