I don't know why this doesn't work, I'm just trying to check if .searchBar
doesn't exist.
var $school = "Washington";
if(!$('.searchBar')){
$('#schoolname').text($school);
}
if($('.searchBar').length === 0){
Remember, jquery always returns a wrapped set of matching elements. The list may be zero though.
Use .length
to find if it exist if(!$('.searchBar').length){
jQuery $()
function always return a jQuery object even if doesn't find any element. So you need to use .length
property of the jQuery object to find if the element actually exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With