简体   繁体   中英

Bootstrap Tooltip NOT A FUNCTION when jQuery DataTables is initialized

Maybe the answer's here and I'm just not seeing it, so any assistance would be most welcome. I have a table, that I'm loading jQuery DataTables onto, plus I'm using Bootstrap, and some of the spans IN the td's have Bootstrap tooltips. The tooltips work fine, just by themselves, since I have the init script in the footer - but when I add the dataTables basic init script, suddenly I get the error:

Uncaught TypeError: $(...).tooltip is not a function

Here's what I have:

HTML5

<table id="resources" class="hover" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Type</th>
                <th>Title</th>
                <th>Thumbnail</th>
                <th>Instrument</th>
                <th>Share</th>
                <th>Resources</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Type</th>
                <th>Title</th>
                <th>Thumbnail</th>
                <th>Instrument</th>
                <th>Share</th>
                <th>Resources</th>
            </tr>
        </tfoot>
        <tbody>
            <tr>
                <td>Video</td>
                <td><a href="#" class="resource-link" data-toggle="modal" data-target="#videoModal">Title of Video</a></td>
                <td><a href="#" class="resource-link" data-toggle="modal" data-target="#videoModal"><img src="thumbnail.jpg" alt="Title of Video" class="img-responsive img-resource"></a></td>
                <td>Insutrment</td>
                <td><a class="btn btn-default btn-xs" data-toggle="modal" data-target="#shareModal">Share <i class="fa fa-share-alt" aria-hidden="true"></i></a></td>
                <td><span class="fa-stack fa-1x" data-toggle="tooltip" data-placement="top" title="Video Resource"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-video-camera fa-stack-1x fa-inverse"></i></span></td>
            </tr>
     </tbody>
</table>

JS

$(document).ready(function(){
     $("#resources").DataTable();
     $('[data-toggle="tooltip"]').tooltip({
          container : 'body'
     });
});

I'm loading in the following libraries:

  • jQuery - 3.2.1
  • Bootstrap - 3.3.7
  • DataTables - 1.10.15

Seems to be working.

 $(document).ready(function() { $("#resources").DataTable(); $('[data-toggle="tooltip"]').tooltip(); }); 
 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="//cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script> <table id="resources" class="hover" cellspacing="0" width="100%"> <thead> <tr title="Tooltip Test"> <th>Type</th> <th>Title</th> <th>Thumbnail</th> <th>Instrument</th> <th>Share</th> <th>Resources</th> </tr> </thead> <tfoot> <tr> <th>Type</th> <th>Title</th> <th>Thumbnail</th> <th>Instrument</th> <th>Share</th> <th>Resources</th> </tr> </tfoot> <tbody> <tr> <td>Video</td> <td><a href="#" class="resource-link" data-toggle="modal" data-target="#videoModal">Title of Video</a></td> <td> <a href="#" class="resource-link" data-toggle="modal" data-target="#videoModal"><img src="thumbnail.jpg" alt="Title of Video" class="img-responsive img-resource"></a> </td> <td>Insutrment</td> <td><a class="btn btn-default btn-xs" data-toggle="modal" data-target="#shareModal">Share <i class="fa fa-share-alt" aria-hidden="true"></i></a></td> <td><span class="fa-stack fa-1x" data-toggle="tooltip" data-placement="top" title="Video Resource"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-video-camera fa-stack-1x fa-inverse"></i></span></td> </tr> </tbody> </table> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM