Set focus on filter input

Set focus on filter input

justStevejustSteve Posts: 49Questions: 8Answers: 1
edited March 2016 in DataTables 1.10

As discussed at: https://datatables.net/forums/discussion/6401/change-the-word-search-to-filter -- perhaps needs to be updated. Out of the box my filter input's markup looks like

<div id="ordersTable_filter" class="dataTables_filter">
<label>
Search:
<input class="" type="search" placeholder="" aria-controls="ordersTable">
</label>
</div>

I've tried both:

$('#ordersTable_filter input:search').focus(); // tosses error

and:

$('#ordersTable_filter input:text').focus(); // doesn't work

This question has accepted answers - jump to:

Answers

  • btreebtree Posts: 99Questions: 14Answers: 11
    Answer ✓

    Hello,

    only use input

      $('#example_filter input').focus();
    

    Fiddle:
    http://live.datatables.net/hoduyawo/1/edit

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    The first one would need to be:

    $('#ordersTable_filter input[type=search]').focus(); // tosses error
    

    There is no :search pseudo class.

    However, as @btree says, just simplify it and drop the pseudo class altogether - it isn't needed as there are no other input elements in that div.

    Allan

  • justStevejustSteve Posts: 49Questions: 8Answers: 1

    Perfect -- mny thx!

This discussion has been closed.