I have the following code which shows a tooltip containing dynamic data. Its working fine, But it shows same tooltip for all.
I have used tip._tippy.destroy();
bit didn't worked.
<div id="template" style="display: none;">
Loading a tooltip...
</div>
Element on which tooltip shows above:
<span class="more-tags otherPostTags" data-postId="{{$post->id}}">...</span>
Js:
const template = document.querySelector('#template')
const initialText = template.textContent
const tip = tippy('.otherPostTags', {
animation: 'shift-toward',
arrow: true,
html: '#template',
onShow() {
const content = this.querySelector('.tippy-content')
if (tip.loading || content.innerHTML !== initialText) return
tip.loading = true
node = document.querySelectorAll('[data-tippy]');
let id = node[0].dataset.postid;
$.ajax({
url: '/get/post/'+id+'/tags',
type: 'GET',
success: function(res){
let preparedMarkup = '';
res.tags.map(function(item) {
preparedMarkup +=
'<span class="orange-tag" style="background-color: '+item.color+'">'+
item.name +
'</span>';
});
content.innerHTML = preparedMarkup;
tip.loading = false
},
});
},
onHidden() {
const content = this.querySelector('.tippy-content');
content.innerHTML = initialText;
},
});
When i hover over, The tooptip shows with tags coming from the database, But it shows same tags/data on hover, The data comes different but it shows tooltip which comes on first hover.
const
? Every variable in your code i mean. – Birkenheadspan
element is the one that triggers the tooltip on hover then grab the id of the tooltip showing by thearia-describedby
attribute onspan
element. You may check what i mean in this fiddle jsfiddle.net/vo1sxzbp/3, hover over a button while inspecting the element on your browser. I hope this is what you mean in your comment. @Chez – Birkenhead