Looking to dynamically load a text file into bootstrap tooltip titles.
Here is a snippet of working code with hardcoded values:
<div>
<a id="A" type="button" class="btn btn-outline-secondary btn-lg" data-toggle="tooltip" dataplacement="bottom" href="Some action"> A</a>
<a id="B" type="button" class="btn btn-outline-secondary btn-lg" data-toggle="tooltip" dataplacement="bottom" href="Some action"> B</a>
<a id="C" type="button" class="btn btn-outline-secondary btn-lg" data-toggle="tooltip" dataplacement="bottom" href="Some action"> C</a>
</div>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
$('#A').tooltip({
title: "June"
});
$('#B').tooltip({
title: "July"
});
$('#C').tooltip({
title: "August"
});
</script>
I have a text file containing:
June
July
August
My goal is to update this text file using a script and dynamically assign these values to the tooltip titles.
I've tried using XMLHttpRequest() and $.get() methods but haven't achieved the desired result.
One attempt was:
function setTooltip(node) {
$.get("My text File", function(responseText) {
var Month = responseText;
});
console.log(Month);
return Month;
}
$('#A').tooltip({
title: setTooltip
});
The console logs the values correctly but the tooltip title remains empty.
Is there a better approach to achieve this? Or a way to iterate through the lines of the file?