Question: `EDIT` Helping people understand the question better

Can you call a argument and then use it in jQuery? I was thinking something like:

```
// Notice the "test" argument in the "foo" function
function foo(test) {
  $("#randomDiv").click(function(){
    $(test).toggle();
  });
}

```

Would something like this work?

Answer: 
You can use pure jQuery to select the first invalid input:

`$('input.ng-invalid').first().focus();`
I did some small modifications to the great solution written by iandotkelly.
This solution adds an animation that is triggered on scroll, and does a focus to the selected element after that.

```
myApp.directive('accessibleForm', function () {
    return {
        restrict: 'A',
        link: function (scope, elem) {

            // set up event handler on the form element
            elem.on('submit', function () {

                // find the first invalid element
                var firstInvalid = elem[0].querySelector('.ng-invalid');

                // if we find one, we scroll with animation and then we set focus
                if (firstInvalid) {
                     angular.element('html:not(:animated),body:not(:animated)')
                    .animate({ scrollTop: angular.element(firstInvalid).parent().offset().top },
                        350,
                        'easeOutCubic',
                        function () {
                            firstInvalid.focus();
                        });
                }
            });
        }
    };
});

```