Not an expert, so I am trying to understand why this condition fails. I want it to set focus on .alert-focus if the css classes are present in the page, otherwise if they are not it should set focus on #maincontent. However it never ends up setting focus on #maincontent.
here is my code:
$(function() {
if ($('body .alert, body .success, body .warning').length) {
$('.alert-focus').focus();
} else {
$('#maincontent').focus();
}
});
<a id="maincontent" tabindex="-1" name="maincontent"></a>