-2

I am building a search engine. How can I have the input tag (type="text") be focused when the page loads so people can start searching straight away without having to click on it?

Just a student
  • 10,560
  • 2
  • 41
  • 69
  • Welcome to Stack Overflow, we expect at least some research before asking a question. There is at least one question on this site that answers exactly this and numerous results on any given search engine. – Jon P Nov 06 '16 at 23:57

2 Answers2

2

You're looking for the autofocus attribute, which does exactly that.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Use jQuery and .focus() method.

$( document ).ready(function() {
    $('#search_input').focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="search_input">
El Danielo
  • 780
  • 1
  • 8
  • 18