The problem is that you are using $ (this)
Using the 'this' keyword context with jQuery
https://remysharp.com/2007/04/12/jquerys-this-demystified
An easy way is to save the link to $ (this) and then use it later.
For instance:
$('a.up_vote').click(function(e) { e.preventDefault(); window.alert("hello"); console.log("hello there"); var $that = $(this); $that.siblings("span").css( "background-color", "green" ); $.ajax({ url: $that.attr('href'), type :'get' , success : function (data){ // alert('success'); console.log('hello from success ajax') console.log(data.count); $that.find("span").css( "background-color", "red" ); $that.siblings('span').html(data.count); $that.siblings("span").css( "background-color", "red" ); // $('#upvote_count').html(data.count); console.log('siblings passed') }, failure : function (data){ alert('failure') ; } }) ; // ajax call }); // upvote link call
$, which is just a var name starting with $, but not specific to jquery as such, but a useful habit for a variable storing jquery objects (including wrapped $ () DOM elements, since they are also jquery objects)
$ this = $ (this) is a useful template to apply using whatever variable names you want.
In addition, a simple console call to check for key variables is always recommended if something doesn't work.
console.log('debug',$(this));
You just press F12 and go to the console tab (or enter the name of your browser + dev console in google if nothing happens) and see what is printed there (or even use breakpoints or another debugging method, see the link)
Link Debugging
Chrome DevTools: https://developer.chrome.com/devtools
JS debugging in Chrome: https://developer.chrome.com/devtools/docs/javascript-debugging