Skip to content Skip to sidebar Skip to footer

Change Tooltip Text Jquery

Suppose the title attribute was used as the text for a tool tip. Is it possible just to change the text, using jQuery? &

Solution 1:

I couldn't get it to change with the option as I believe the api says using title is to tell it what the value should be if the title is not there. I got it to work by changing the title to be data-title and gave the title option as a function that returns this value.

$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip({
      title: function () {
        return this.getAttribute('data-title');
      }
    });
    
    setInterval(function(){
      $('[data-toggle="tooltip"]').attr('data-title', Date.now());
    }, 1000);
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <h3>Tooltip Example</h3>
  <a href="#" id="tool" data-toggle="tooltip" data-title="Hfdfd!">Hover over me</a>
</div>

Post a Comment for "Change Tooltip Text Jquery"