Bootstrap add tooltip to dropdown

19,027

Solution 1

Check you have linked everything up correctly and included the bootstrap.js file. I have set up a JSFIDDLE with your code and the tooltip works:

http://jsfiddle.net/shannabarnard/ueoxmm9v/

<div class="btn-group" style="margin-bottom:5px; width: 100%;">
    <a id="tableNameButton" data-placement="bottom" title="Text" class="my-tooltip my-dropdown tableNameButton btn btn-default btn-block btn-select" data-toggle="dropdown" href="#">Select table <span class="caret"></span></a>

    <form:input class="form-control" id="tableNameFormId" path="tableName" style="visibility: hidden; display: none;" />
    <ul id="tableName" class="dropdown-menu scrollable-menu">
             <c:forEach items="${databaseTables}" var="databaseTable">
                  <li><a href="#">${databaseTable}</a></li>
             </c:forEach>
    </ul>
</div>

JS

$('.my-dropdown').dropdown();
$('.my-tooltip').tooltip();

Solution 2

I suppose it doesn't work because you didn't add data-attributes like data-toggle and data-placement. Try to add them and I think it'll work.

See fiddle with working example: http://jsfiddle.net/h56xw8wq/1/

You should have smth like

<li class="dropdown" id="example" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom" > ... </li>

Hope it'll help you:)

Share:
19,027
Steve
Author by

Steve

Good experience in modern development tools and frameworks. Focused on timely results, fast learner, capable of quick implementation of the new skills in complex projects. Self-motivated, pro-active and friendly team player. Able to work under time pressure, highly committed. Proven by work experience in Alabama, USA and recent IT projects for international clients - strong English and customer service skills.

Updated on July 16, 2022

Comments

  • Steve
    Steve almost 2 years

    I am trying to add tooltip to Bootstrap, tried all solutions found on internet - nothing helps. Here is my dropdown(I am also using String and jstl tags):

        <div class="btn-group" style="margin-bottom:5px; width: 100%;">
                  <a id="tableNameButton" data-placement="bottom" title="Text" class="my-tooltip my-dropdown tableNameButton btn btn-default btn-block btn-select" data-toggle="dropdown" href="#">Select table <span class="caret"></span></a>
                  <form:input class="form-control" id="tableNameFormId" path="tableName" style="visibility: hidden; display: none;" />
                  <ul id="tableName" class="dropdown-menu scrollable-menu">
                         <c:forEach items="${databaseTables}" var="databaseTable">
                                 <li><a href="#">${databaseTable}</a></li>
                         </c:forEach>
                  </ul>
        </div>
    

    And on javascript:

    $('.my-dropdown').dropdown();
    $('.my-dropdown').tooltip();
    

    This thing doesn't work. Hope someone already solved this problem, thanks in advance.

  • Steve
    Steve over 9 years
    Thank you, now I understand that it's not the problem with this code.