Reputation: 471
$(".eventer button[name=myBtn]").click(function() {
console.log('clicked');
thisBtn = $(this);
parent = $(this).parent();
num = parent.data('num');
id = parent.data('id');
if(typeof num != 'number'){
num = 0;
}
$(this).attr('disabled', true);
$.post('javas.php', {num: (num-1), id: id}, function(data) { console.log('Ajax success');
parent.next('.status').html(data);
thisBtn.attr('disabled', false); // reset });
console.log('Ajax success');
parent.data('num', --num);
parent.next('.status').html(data);
thisBtn.attr('disabled', false); // reset
} );
} );
console.log('-- end');
});
How would i get the id of the class that has been clicked on, this is what i have so far, i want to send the id of the post along with the value of num (already being sent). How would i do this, thanks any help is appreciated!
Upvotes: 1
Views: 117
Reputation: 5042
Although class attribute in tag is called 'class' , in javascript 'class' is a reserved keyword therefore you should use:
$(this).attr('className')
Upvotes: 0
Reputation: 14863
To get the id, simply do
var id = this.id;
EDIT: $(this).attr('id')
also works, but why do it the hard way? this.id
is pure Javascript
Upvotes: 6
Reputation: 37665
You can just get the ID from the attributes:
var theId = $(this).attr( "id" );
Upvotes: 1