I am trying to use bootstrap tooltip in my laravel project.
Here's my blade.php code:
...
@foreach($patients => $patient)
...
//This is the tooltip button
<div data-toggle="tooltip" class="btn btn-default comment-tooltip" data-patient-id="{{ $patient->patient_id }}"><i class="fa fa-book" aria-hidden="true"></i></div>
//this is the div i wanna show after hovering tooltip button
<div id="{{$patient->patient_id}}" style="visibility: hidden">
some text
</div>
...
@endforeach
...
And here's my javascript code
$(document).ready(function() {
$('.comment-tooltip').tooltip({
title: function () {
var patient_id = $(this).data('patient-id');
var element = document.getElementById(patient_id);
element.style.visibility = 'visible';
return element;
},
html: true,
placement: 'right',
callback: function(){
var patient_id = $(this).data('patient-id');
var element = document.getElementById(patient_id);
element.style.display = 'none';
}
});
});
And when I hover the button on first time, it works
But when I hover it on second time, it shows error message below in console
Uncaught TypeError: Cannot read property 'style' of null
Hope someone can help me fix this problem. Thanks!!