user2449026
user2449026

Reputation: 457

Bootstrap 3 Tooltip over Glyphicon

Not sure if this even possible, I am trying to invoke a tooltip over a glyphicon inside an input group, my code (which does not work) is;

<div class="input-group">
<input type="text" class="form-control" name="security" id="security"><span class="input-group-addon"><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-container: 'body' title="" data-original-title="Security Code"></span></span>
</div>

I'm using Bootstrap 3, and the latest version of jQuery.

Upvotes: 33

Views: 71083

Answers (5)

Dennis
Dennis

Reputation: 59557

You can get a simple tooltip over the glyphicon using the title attribute (which is blank in your example).

title="info"

Working code

 // add this in your js
 // all the glyphicons having the class "my-tooltip" will show a tooltip if "title" attribute is present
 $(".my-tooltip").tooltip();

 <span class='glyphicon glyphicon-info-sign my-tooltip' title="here goes the tooltip text"></span>

Upvotes: 77

Hamza Khanzada
Hamza Khanzada

Reputation: 1529

Using Bootstrap's Popover makes it a bit nice, Here is the documentation, and sample code snippet

$(function () {
  $('.fa').popover({trigger: "hover"});
})
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Information Popover snippet">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Information Popover snippet</title>
  <script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
</head>
<body>  
  <span><i data-content="Simple Clean way to show more detailed information about anything" class="fa fa-question-circle"></i></span>
</body>
</html>

Upvotes: 3

Web_Developer
Web_Developer

Reputation: 1251

<span class="glyphicon glyphicon-info-sign icon_info" title="info"></span>

Then add javascript code to initialize tooltip like below:

$(".icon_info").tooltip();

Upvotes: 5

acrawly
acrawly

Reputation: 453

Using @MadJack's answer I rewrote your code and tested on JSFiddle.

HTML:

<div class="input-group" style='margin-top: 100px;'>
    <input type="text" class="form-control" name="security" id="security">
        <span class="input-group-addon">
            <a class='my-tool-tip' data-toggle="tooltip" data-placement="left" title="Tooltip here">
                <!-- The class CANNOT be tooltip... -->
                <i class='glyphicon glyphicon-info-sign'></i>
            </a>
        </span>
    </input>
</div>

JS:

$("a.my-tool-tip").tooltip();

Hope this helps,

JSFiddle.

-Andrew

Upvotes: 22

jackfrosch
jackfrosch

Reputation: 314

A Bootstrap newbie here...

To use the Tooltip plugin with the glyph-icon, I've found success wrapping the glyph-icon span tag with an anchor tag having no href:

<a data-toggle="tooltip" class="tooltipLink" data-original-title="Tooltip text goes here">
  <span class="glyphicon glyphicon-info-sign"></span>
</a>

Also, be sure to initialize the tooltips for the links with tooltips:

$("a.tooltipLink").tooltip();

I tested this with Bootstrap 3.03, jQuery 1.10.2 + Firefox 26, Chrome 32.0.1700, and IE 11.0.9600. So far, no hiccups.

Upvotes: 5

Related Questions