Could perhaps improve readability a bit here by using the jQuery `hasClass` method?