Search code examples
javascriptsetfocus

Set focus on dataTable in javascript


<table id="table-dispatch" class="display data-table" cellspacing="0" width="100%"  onclick="showrequestmap()">
        <thead>
          <tr>
            <th> ID </th>
            <th> Status </th>
            <th> Client </th>
            <th> Client Phone Number </th>
            <th> Dispatch Date </th>
            <th> Driver </th>
            <th> Distance </th>
            <th> Current Location </th>
            <th> Estimated Fare </th>
            <th> Action </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>5</td>
            <td> Waiting for pickup </td>
            <td> Raj </td>
            <td> 85115 </td>
            <td> Apr 18, 2016 7:07 PM </td>
            <td> tushar patel </td>
            <td> NaN </td>
            <td> Thaltej, Ahmedabad, Gujarat 380054, India </td>
            <td> 0$ </td>
            <td> action </td>
          </tr>
        </tbody>
      </table>
    </div>

this is my DataTable. And how to set focus method on DataTable in JavaScript.

$(document).ready(function(){
  $("#table-dispatch").focus(function() {  
  });
});

this is my JavaScript code.i try focus method on DataTable Id. But it does not work. so how can i focus method use on DataTable. please give me solution. And how give first priority to focus method before on-click Method.


Solution

  • just look at these code, it's not hover, but i achieve the same functionality by mouseover() function.

    jsFiddle : https://jsfiddle.net/eua98tqa/12/

    jQuery:

    $('#table-dispatch').mouseover(function(){
      $(this).css('background-color','#ddd');
    }).mouseout(function(){
      $(this).css('background-color','#bbb');
    });