I am using materializecss in my app script add-on, When I try and add a tooltip dynamically the tip does not update with the new label. I have tried several variations and even double-checked that the tip was being changed, which it was. The problem is that it does not seem to reinitialize with the updated text.
Here is a jfiddle: https://jsfiddle.net/edlisten/grafo4su/1/
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>
<script>
$(function() {
$('.tooltipped').tooltip({delay: 50,tooltip:"new",position:"bottom"});
});
</script>
</head>
<body>
<div class="container">
<a class="btn tooltipped">Hover me!</a>
</div>
</body>
</html>
What you can do is set an id to the anchor.
Lets say <a class="btn tooltipped" id="tooltip">Hover me!</a>
Now we can find easily the element with jquery.
var anchorElement = $('#tooltip');
Materialize has an atribute data-tooltip
you need to have on the element so that the tooltip will pop out.
anchorElement.attr('data-tooltip', 'New tooltip value');
And finally we need to initialize the materialize tooltip on the element
anchorElement.tooltip();
You can play around with it and put it in a function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With