tooltip("show") method in Bootstrap


Use the tooltip(“show”) method in Bootstrap to display the tooltip. As shown below that the tooltip is visible on button click:

$(document).ready(function(){
  $(".btn-primary").click(function(){
    $("[data-toggle='tooltip']").tooltip('show');
  });
});

The tooltip would be visible on a link wherein I have set the data-toggle attribute and the link text as shown in the following code snippet −

<a href="#" data-toggle="tooltip" title="Tooltip is visible!">
  On clicking the below button, the tooltip would be visible.
</a>

You can try to run the following code to implement the tooltip(“show”) method −

Example

Live Demo

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <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>
  </head>

<body>
  <div class="container">
    <h3>Demo</h3>
    <a href="#" data-toggle="tooltip" title="Tooltip is visible!">On clicking the below button, the tooltip would be visible.</a>
    <div>
      <button type="button" class="btn btn-primary">Click me</button>
    </div>  
  </div>

<script>
$(document).ready(function(){
  $(".btn-primary").click(function(){
    $("[data-toggle='tooltip']").tooltip('show');
  });
});
</script>

</body>
</html>

Updated on: 16-Jun-2020

190 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements