ASP.Net C# Creating an AutoFocus property in your Master Page

ASP.Net C# Creating an AutoFocus property in your Master Page

by Matthew Pavey

HTML

<p>Notice that the <strong>firstname</strong> input gets the focus since it is the first input control that is enabled, visible, and does not have a noautofocus class.</p>
<input type="text" id="disabled" disabled="disabled" placeholder="disabled" />
<br />
<input type="text" id="hidden" style="display: none" placeholder="hidden" />
<br />
<input type="text" id="excluded" class="noautofocus" placeholder="noautofocus" />
<br />
<input type="text" id="firstname" placeholder="firstname" />
<br />
<input type="text" id="lastname" placeholder="lastname" />
<br />
<p>See original post at <a href="http://www.pavey.me/2015/04/aspnet-c-creating-autofocus-property-in.html" target="_blank">http://www.pavey.me/2015/04/aspnet-c-creating-autofocus-property-in.html</a>
</p>

JavaScript

$(document).ready(function () {
    $(':input:enabled:visible:not(.noautofocus):first').focus();
});