Need not to write additional js code, cause this functionality already exists in Bootstrap. Let me suppose that you need not to hide after seconds, but you need to remove annoying tooltip if it already has been read. If you need behavior such as auto-hide Bootstrap tooltip (or popover) on focus out or click anywhere outside of tooltip, use and stylize element which can be in focus. For instance BUTTON.
In template use code:
<button class="tooltip-button"
role="button"
data-toggle="tooltip"
data-placement="right"
data-html="true"
data-trigger="focus hover"
data-title="Your tooltip html code or text">*</button>
Style with SCSS to introduce button as regular text:
button.tooltip-button {
cursor: pointer;
border: none;
background-color: transparent;
padding: 0;
&:not(:disabled) {
outline: none;
}
}
And don't forget in your base template initialize all tooltips on page:
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip();
})
</script>