I have a problem with my tooltip. When I do a product search, the information is loaded via javascript. After placing the icon with the tooltip next to the label, it stops working.
Code in HTML:
<label class="fg-label control-label" for="xGrade">Estoque <i class="zmdi zmdi-help zmdi-hc-fw" data-toggle="tooltip" data-placement="top" id="xLocalEstoqueQuantidade" title="" data-trigger="hover"></i></label>
Code in javascript:
document.getElementById('xLocalEstoqueQuantidade').setAttribute('title', suggestion.xNomeEstoqueAtual);
$('[data-toggle="tooltip"]').tooltip({ trigger: 'hover'});
Sample video: https://www.loom.com/share/96d23f5e191b4c5bae9c0c59068cf120
I want that when you hover the mouse it displays the message
CodePudding user response:
Your code looks fine, but I am not able to check few things, so please check:
- dependencies. To display tooltip you need jquery, popper, bootstrap. Be aware the order is important.
- value that you want to put in the title. Please look if
suggestion.xNomeEstoqueAtual
object is not empty.
I prepare a workable solution, so it should help you.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA 058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<h1>Hello, world!</h1>
<button id="my-special-button" type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="">
Tooltip on top
</button>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 76PVCmYl" crossorigin="anonymous"></script>
<script>
$(() => {
$('#my-special-button').attr('title', "Our dynamic data")
$('[data-toggle="tooltip"]').tooltip()
})
</script>
</body>
</html>