Forum Moderators: open
if ( ($('p#test').css('opacity') !== 0) ) $('p#test').append('<span class="add"> yes</span>'); if ( ($(p#test).css('opacity') !== 0) && ($('p#test span').hasClass('add')) ){ do something } ? It would be logically better to test if there actually is a span
const spanElem = document.querySelector('#test span')
if (spanElem) { //do something }
//if you are coding using ES5 (eg for older browsers use var instead of const)