You have syntax errors in your code. You are using the "CSS Slector" syntax instead of the method. The other issue is you are expecting $(this) to be all the spans when it is just the one you clicked on.
var spans = $('.icon-appointment span');
spans.on("click", function () {
var currentSpan = $(this);
var prevIndex = currentSpan.index() - 1;
var prevSpan = spans.eq(prevIndex);
console.log(prevSpan.hasClass('active-icon-green'));
});
Now if they were siblings in the HTML, you can just use prev()
var spans = $('.icon-appointment span');
spans.on("click", function () {
var currentSpan = $(this);
var prevSpan = currentSpan.prev();
console.log(prevSpan.hasClass('active-icon-green'));
});
And after the 4th edit....
The class is on the <i>
not the span. So you would need to look at the <i>
var prevSpan = spans.eq(prevIndex);
var prevIcon = prevSpan.next("i");
console.log(prevIcon.hasClass('active-icon-green'));