I am attempting to display 1 of 2 titles based on whether some DOM elements can be found / visible around the page. For whatever reason, it isn't working... Here's the live demo to date.

I have got the next code:

$('h3.list_heading').css('display', 'none');
$('h3#error').css('display', 'none');
    if ( $('div.availableNowListing').filter(':visible').length == 0) {
        $('h3#error').css('display', 'block');
    } else {
        $('h3.list_heading').css('display', 'block');
    }

Right now, regardless of what I choose I only find yourself getting one heading displayed...

EDIT Simply to explain what should happen: When hitting the shop to sort by, it will only display records that's connected with this store. If there is no fruit connected with this store, the heading:

Our Suggestion of the greatest Obtainable in xxxxx now

should switch to

Misfortune! It appears we could't find worthwhile fruit at xxxxx store now

EDIT 2 Attempted while using following code, but nomatter which store I choose to sort by, I simply obtain the error message even when the div's I am searching for can be found...

$('h3.list_heading').hide();
$('h3#error').hide();
if ( $('div.availableNowListing:visible').length) {
    $('h3#error').show();
} else {
    $('h3.list_heading').show();
}

Unsure if it can help, but try altering the code to:

$('h3.list_heading').hide();
$('h3#error').hide();

if ($('div.availableNowListing:visible').length) {
    $('h3#error').show();
} else {
    $('h3.list_heading').show();
}
function onscreen_sort (get_store) {
  var check = false;
  $('div.availableNowListing').each( function() {
      // Reset Display
      var correct = $(this).children('.' + get_store).not(':first-child')
      var incorrect = $(this).children(':not(.' + get_store + ') ').not(':first-child')

      if(correct.length > 0) record = true;

      correct.find(":hidden").fadeIn('fast');  //only hide which is not correct ->less dom overlow
      incorrect.find(":visible").fadeOut('fast'); //any only show which is correct but hidden
  });
  check_heading(check)
}

function check_heading(boo) {
  $('h3#error').hide();
  $('h3.list_heading').hide();    

  if (boo) {
      $('h3.list_heading').show();
  } else {
      $('h3#error').show();
  }
}

switch ( store_selected ) {
  case "all" : 
      var class_match = "in_all"
      onscreen_sort(class_match);
      $('span.store_change').text( ' All Stores' );
      $('div.availableNowListing').not(':first').find('div.available_now_entry').fadeOut('fast');
      //check_heading();  //no more needed!
      break;

  case "asda" : 
     ...
     ...
     ...

I really hope this works. God luck!

Try altering wrinkles inside your switch

$('div.availableNowListing').not(':first').find('div.available_now_entry').fadeOut('fast');
check_heading();

for this rather, shifting the function call like a callback for fadeOut().

$('div.availableNowListing').not(':first').find('div.available_now_entry').fadeOut('fast',  check_heading);