How to create a function for this code?
Hi,
My code looks like this:
- var firstInput = $('#user-login-form :input:enabled:visible:first');
- firstInput.focus();
- firstInput.addClass('dirty');
- firstInput.prev('label').addClass('dirty');
- $('.js-signInButton').click(function(e){
- e.preventDefault();
- $('#edit-email').focus();
- var firstInput = $('#user-login-form :input:enabled:visible:first');
- firstInput.focus();
- firstInput.addClass('dirty');
- firstInput.prev('label').addClass('dirty');
- });
- $('.js-registerButton').click(function(e){
- e.preventDefault();
- $('#edit-firstname').focus();
- var firstInput = $('#user-register-form :input:enabled:visible:first');
- firstInput.focus();
- firstInput.addClass('dirty');
- firstInput.prev('label').addClass('dirty');
- });
However as you can see the part which put the focus on the first input is repeating almost 3 times with the difference that var firstInput has different values.
The code is working but it doesn't look nice and clean. How can I make a function from the part which put the focus on the first input and call it whenever I need it?
Thanks