BetterLateThanNever
BetterLateThanNever

Reputation: 906

Auto focus on search box of jQuery DataTable

I am unable to find a way to auto focus on jQuery Datatable's Search Box on page load.

The problem here is that this Text box is not given a ID and so i'm unable to access it.

Can someone help me with this issue.

An example of Datatable is at https://datatables.net/examples/advanced_init/html5-data-options.html

Thanks!

Upvotes: 1

Views: 5675

Answers (1)

Nalin Aggarwal
Nalin Aggarwal

Reputation: 888

You can do this with jquery:

$(function() {
    $("#datatabelID [type='search']").focus();
});

or

$("div.dataTables_filter input").focus();

Just use your datatable Id with the above selector, and you are bale to access the search textbox.

Upvotes: 6

Related Questions