Scroll to first error in jQuery without a warning in JavaScript console : I am using below code - $( 'html, body' ).animate({ scrollTop: ($( '.has-error' ).first().offset().top) }, 500); The above code is working fine but there is one small issue. The Issue Is - when no one field are required in the form I am getting below issue. In JavaScript console, I get error - TypeError: $(...).first(...).offset(...) is undefined Solution Is – check the length of invalid CSS is grater then zero. var scrollIntoAppView = function () { var elt = $( ".ng-invalid" ); if (elt.length) { $( 'html, body' ).animate({ scrollTop: (elt.first().offset().top) }, 500); } } OR var elm = $( 'input.ng-invalid select.ng-invalid'...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers