$(this).css('display', '')
is an expression that evaluates to a value - what it evaluates to is the $(this) jQuery object, which has also had its display changed. So the condition
if($(this).css('display', '')){
will always be satisfied, because objects are truthy.
Use $(this).css('display') === 'none' instead (one argument) to retrieve the current computed display style.
if ($('div').css('display') === 'none') {
console.log('Div hidden');
} else {
console.log('Div not hidden');
}
if ($('span').css('display') === 'none') {
console.log('Span hidden');
} else {
console.log('Span not hidden');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div></div>
<span style="display: none"></span>
Keep in mind that
this.style.display
checks the display property on the element itself, whereas
$('div').css('display')
checks the computed display property. The element may have a display applied (eg, from CSS like div { display: none }) despite not having a display property of the element's own style object.