1👍
✅
this.id
is undefind
inside $.get
. SO you should change your code like this
$(document).ready(function() {
$('.vote_up').on('click', function() {
var id = this.id;
$.get("/vote_up/" + id + "/", function(data) {
$('#voted' + id).html(data);
});
});
$('.vote_down').on('click', function() {
var id = this.id;
$.get("/vote_down/" + id + "/", function(data) {
$('#voted' + id).html(data);
});
});
});
0👍
You can use Jquery addClass()
method to assign classes dynamically to an element.
Example :
$("#ID").addClass("selected");
Or if you just want to add an style to and element you can use css()
method
Example:
$("#ID").css( "color", "red" );
Hope this may help you
- How to display data from json retrieved from django-rest-framework?
- How to have multiple types of users in separated tables?
- SHOP_CURRENCY_LOCALE = 'en_US.UTF-8'
- Following button on site not working
Source:stackexchange.com