When the page loads, I want to focus and highlight (border color or background color change) an input control. How can I do it? This is what I got so far.
<script type="text/javascript">
$(function () {
$("#txt1").focus();
});
</script>
Take a look at CSS
:focusselector. And just specify CSS class like:As it is not supported by older browsers (IE7 plus some other). You may want to do that with JS.
Where
focusedis defined like this:EDIT:
Jquery.focus docs.
Line above simply binds a handler to focus event and does not change a focus or execute it immediately. In order to get a field focused on page load another line should be added after that one:
This one will set a focus on selected element and run a handler attached previously.
Shorter notation:
Demo with element autofucused on page load