How do i set focus to the Search box?

How do i set focus to the Search box?

mithun_daamithun_daa Posts: 11Questions: 0Answers: 0
edited January 2012 in General
I have tried numerous things with no success. Any help would be greatly appreciated.

I have 3 datatables on the page and following give me the correct DOM element
[code]$('.dataTables_filter input').first()[/code]

but the focus does not work
[code]$('.dataTables_filter input').first().focus();[/code]

I am using Twitter Bootstrap if that has anything to do with it.

Thanks.

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    [code]
    $('div.dataTables_filter input').focus();
    [/code]

    should do it. I use it on this page: http://datatables.net/ref

    Allan
  • mithun_daamithun_daa Posts: 11Questions: 0Answers: 0
    Great!!!. That worked. Thanks.
  • fidelfidel Posts: 7Questions: 1Answers: 0
    and how would i check if the focus is in the search field in the first place?
This discussion has been closed.